未找到laravel Class'App \ Categories'

时间:2018-01-11 06:05:56

标签: laravel

当我尝试调用类别数据为$categories = Categories::all();的函数时,会返回Class 'App\Categories' not found

的错误

这是我的CategoriesController代码:

namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller as BaseController;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;
use App\Categories;


class CategoriesController extends BaseController
{
    public function listcategories() {
    $categories = Categories::all();
    dd($categories);
    return view('admin.list_categories')->with('listcategories', 
    $categories);
}

这是我的分类型号代码;

  namespace App; 
  use Illuminate\Http\Request;
  use Illuminate\Database\Eloquent\Model;
  use Illuminate\Support\Facades\DB;
  use Illuminate\Support\Facades\Input;

  class Categories extends Model
  {
    protected $fillable = [
    'title',
    'description',
    'flag_image',
    'status'
 ];

const STATUSES = [
    'Active' => 'Active',
    'Inactive' => 'Inactive',
];

const DEFAULT_STATUS = 'Active';
/**
 * Indicates if the model should be timestamped.
 *
 * @var bool
 */
public $timestamps = false;

public static function rules() {
    return [
        'title' => 'required|string|max:255',
        'status' => 'required|string|in:' . implode(",", Categories::STATUSES)
    ];
}}

有什么问题?我无法得到它。

1 个答案:

答案 0 :(得分:1)

因为模型是通过作曲家

进行自动加载的

在某些情况下,您需要运行 更改后composer dump-autoload以使其正常工作