未找到 Laravel 4 模型类

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14284472/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 07:29:04  来源:igfitidea点击:

Laravel 4 Model class not found

laravellaravel-4

提问by duality_

I just created a simple app in Laravel 4 and when I create a model, I get an exception that it's not found.

我刚刚在 Laravel 4 中创建了一个简单的应用程序,当我创建一个模型时,我得到一个找不到它的异常。

// /app/models/Worker.php:
<?php

class Worker extends Eloquent {}

And then in the Controller

然后在控制器中

var_dump(Worker::find(1));

This gives me Error: Class 'Worker' not found. What am I doing wrong? This used to work in Laravel 3 and also watching the screencasts it seems like this should work.

这给了我错误:找不到“工人”类。我究竟做错了什么?这曾经在 Laravel 3 中工作,并且还可以观看截屏视频,这似乎应该可以工作。

回答by anthony.c

Anytime you create a new class file in L4 run this command.

每当您在 L4 中创建新类文件时,请运行此命令。

php composer dump-autoload

回答by Joeri

I think there are two commands to get the autoload started:

我认为有两个命令可以启动自动加载:

$ composer dump-autoload  

and

$ php artisan dump-autoload

Seems composer dump-autoload is to let composer create autoloads as defined in the composer.json files. And php artisan dump-autoload glues all the composer dump-autoloads ( also from vendors and workbenches ) together.

似乎 composer dump-autoload 是让 Composer 创建在 composer.json 文件中定义的自动加载。php artisan dump-autoload 将所有 composer dump-autoloads(也来自供应商和工作台)粘合在一起。