Laravel 5.0,无法重新声明类App\models\Category

Yas*_*svi 6 model runtime-error redeclaration laravel-5

我最近将我的项目从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
Run Code Online (Sandbox Code Playgroud)

这是我的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');
  }
}
Run Code Online (Sandbox Code Playgroud)

我在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;
  }
Run Code Online (Sandbox Code Playgroud)

如果您需要代码中的任何其他内容,请告诉我们.我一直试图找出解决方案已有一段时间了.

Ada*_*dam 10

这是因为您已生成一个控制器,然后将其拖动到子文件夹.您需要将命名空间更改为正确的命名空间或正确生成控制器.

php artisan make:controller Api/CategoryController  
Run Code Online (Sandbox Code Playgroud)

或将名称空间更改为

namespace App\Http\Controllers\Api;
Run Code Online (Sandbox Code Playgroud)

(如果api是控制器所在文件夹的名称)