首页 > 解决方案 > Laravel 雄辩的更新功能

问题描述

在模块化开发中使用 Laravel eloquent。保存效果很好,但更新功能没有像我预期的那样工作。请检查我的编码方法和错误。

use Modules\Projects\Entities\Project;
public function update(Request $request, $id)
    {
        $project = Modules\Projects\Entities\Project::find($id);
        $project->project_name = request('project_name');
        $project->save();
}

错误抛出如下:

{
    "message": "Class 'Modules\\Projects\\Http\\Controllers\\Modules\\Projects\\Entities\\Project' not found",
    "exception": "Symfony\\Component\\Debug\\Exception\\FatalThrowableError",
    "file": "D:\\XMAPP\\htdocs\\minidmsapi\\Modules\\Projects\\Http\\Controllers\\ProjectsController.php",
    "line": 69,
    "trace": [

如何$flight = App\Flight::find(1);在模块化开发中使用“”? Laravel 官方文档

标签: laravelapieloquentinsert-update

解决方案


尝试添加\之前Modules\Projects\Entities\Project::find($id);

喜欢\Modules\Projects\Entities\Project::find($id);

或者您可以直接使用Project::find($id);,因为您已经使用过命名空间。


推荐阅读