我测试laravel 5我有控制器名称Usercontroller.php有代码:
class UserController extends Controller
{
protected $user = null;
public function __construct(User $user)
{
$this->user = $user;
}
public function allUsers()
{
return $this->user->allUsers();
}
}
我创建模型名称user.php有代码:
class User extends Model
{
public function allUsers()
{
return self::all();
}
}
当我运行它时显示如下错误
ReflectionException in compiled.php line 1049: Class App\Http\Controllers\User does not exist
请帮我解决这个问题,谢谢。
答案 0 :(得分:2)
User
模型位于命名空间App
中,您必须像这样引用它:
public function __construct(\App\User $user)
{
$this->user = $user;
}
或者在顶部添加一个import语句:
use App\User;
class UserController extends Controller