Home:ALL Converter>Laravel eloquent Update Function

Laravel eloquent Update Function

Ask Time:2019-10-17T18:19:32         Author:Abhilash KM

Json Formatter

Using Laravel eloquent in Modular development. Save works well, But the Update function not working as I expected. Kindly check my coding method and error.

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();
}

Error throws like:

{
    "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": [

How to use " $flight = App\Flight::find(1);" in modular development ? Laravel Official Doc

Author:Abhilash KM,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/58430271/laravel-eloquent-update-function
Jithesh Jose :

You already imported the Modules\\Projects\\Entities\\Project;.Now you can directly use Project.\n\nuse Modules\\Projects\\Entities\\Project;\npublic function update(Request $request, $id)\n{\n $project = Project::find($id);\n $project->project_name = request('project_name');\n $project->save();\n}\n\n\nHope this helps...",
2019-10-17T10:24:28
Vibha Chosla :

try adding \\ before Modules\\Projects\\Entities\\Project::find($id);.\n\nlike \\Modules\\Projects\\Entities\\Project::find($id);\n\nor you can directly use Project::find($id); as you have already used namespace.",
2019-10-17T10:22:58
yy