gpt4 book ai didi

laravel - 在路由回调函数中使用 Eloquent 模型会出错

转载 作者:行者123 更新时间:2023-12-05 03:12:26 24 4
gpt4 key购买 nike

为什么我不能在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com