我最近将我的项目从 laravel 4.2 升级到 laravel 5.0 并且遇到了几个错误。
我没有在 4.2 版本中定义任何命名空间,但正如这里所建议的,
我已经开始在我的代码中定义命名空间。我不知道我面临的问题是否与此有关,但它发生在此过程的中间。
运行代码时出现以下错误:
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');
}
}
我在 SO 上搜索了类似的错误,但没有找到。
这是我的控制器中在“/”路由上调用的函数。
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;
}
如果您需要代码中的其他内容,请告诉我。我一直试图找出解决方案已经有一段时间了。