为什么我不能在 routes.php 中使用 Eloquent 模型。
像这样
Route::get('image', function(){
$user= [
"image_name" => 'one'
];
User::create($user);
});
我还尝试了 use App\Users;
和 namespace App
它给出了错误。
在深入研究 Controller 之前,我需要检查路由本身的一些内容。 如何在 routes.php 中实现这项工作?
最佳答案
你需要添加
use App\User;
到 Routes.php
的顶部
注意:App\User
,而不是App\Users
。
关于laravel - 在路由回调函数中使用 Eloquent 模型会出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33722991/