Laravel有效更新功能

问题描述 投票:0回答:1

在模块开发中使用雄辩的Laravel。保存效果很好,但是更新功能无法按预期工作。请检查我的编码方法和错误。

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 Official Doc

laravel api eloquent insert-update
1个回答
0
投票

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

例如\Modules\Projects\Entities\Project::find($id);

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

© www.soinside.com 2019 - 2024. All rights reserved.