我最近將項目從laravel 4.2升級到了laravel 5.0,並且一直面臨着一些錯誤。Laravel 5.0,無法重新聲明class App models Category
我沒有在4.2版本定義任何命名空間,但建議here,
我已經開始在我的代碼定義命名空間。我不知道我面臨的問題是否與此有關,但是發生在這個過程中。
我收到以下錯誤,同時運行的代碼:
exception 'Symfony\Component\Debug\Exception\FatalErrorException' with
message 'Cannot redeclare class App\models\Category' in
/Users/yash/summers/lightsCameraDinner/lcd_updated/app/models/Category.php:19
這裏是我的Category.php:
<?php namespace App\models;
use Eloquent;
class Category extends Eloquent {
protected $table = 'categories';
protected $guarded = array('id');
// Defining 'Many to Many' Relationship with 'VendorProfile' Model
public function clients() {
return $this->belongsToMany('Client');
}
// Defining 'One to Many' Relationship with 'Job' Model
public function jobs() {
return $this->hasMany('Job');
}
}
我搜索上這樣類似的錯誤,但沒有找到任何。
這是我的控制器在「/」路由上調用的函數。
public function getIndex() {
$categories = Category::all();
$messages = Message::groupBy('receiver_id')
->select(['receiver_id', \DB::raw("COUNT('receiver_id') AS total")])
->orderBy('total', 'DESC')
->get()
->toArray();
$vendors_ids = array();
foreach ($messages as $message) {
$vendors_ids[] = $message['receiver_id'];
}
$clients = Client::where('profile_type', 'VendorProfile')
->where('is_activated', 1)
->whereIn('id', $vendors_ids)
->limit(4)
->get();
if($clients->count() < 4) {
$clients = Client::where('profile_type', 'VendorProfile')
->where('is_activated', 1)
->limit(4)
->get();
}
Log::info('getIndex function of PagesController');
$this->layout = View::make('layouts.homepage');
$this->layout->content = View::make('pages/index', ['categories' => $categories, 'clients' => $clients]);
return $this->layout;
}
讓我知道你是否需要代碼中的其他東西。我一直試圖找出解決方案相當長一段時間了。
你有另一個'Category Class'在相同的命名空間嗎? – DavidDomain
不,我不知道。 我之前在全局名稱空間中已經擁有了所有內容,因此當時我只能想到這個錯誤。其次,這個類別位於App \ models命名空間中,並且在此命名空間中沒有任何其他名爲model的類。 – Yashasvi
錯誤指向Category.php:19,這就是文件結束的地方。那是什麼意思? – Yashasvi