Kareem Elsharkawy
Kareem Elsharkawy

Reputation: 439

laravel passport return data with eloquent

I need to return message but I get an error.

My controller:

    $user = User::findOrFail($id) ;
    $user->name = $request->input('name');
    $user->email = $request->input('email');
    $user->password = $request->input('password');
    $user->role_id = $request->input('role_id');
    if($user->update()){
        return new UserResource($user);       
    }

I tried:

        return new UserResource($user)->with('status', 'Profile updated!');    

Upvotes: 1

Views: 91

Answers (1)

Jerodev
Jerodev

Reputation: 33196

You have to place the creation of the UserResource instance between brackets so php knows you are using the with function on this new instance.

return (new UserResource($user))->with('status', 'Profile updated!');

Upvotes: 3

Related Questions