user6411346
user6411346

Reputation:

update function is not working

I am trying to update my database for a user by this code , but it is not working . there is no change by the way!

 public function update( Request $request)
    {

        $request->user()->tasks()->where('id', '=', $request->id)->update([
            'name' => $request->title,
            'body' => $request->body,
        ]);


        return redirect('/request');

    }

Upvotes: 0

Views: 62

Answers (2)

user1669496
user1669496

Reputation: 33058

If you already know the id of the task, make it easy on yourself.

Task::find($request->id)->update([
    'name' => $request->title,
    'body' => $request->body
]);

Upvotes: 0

sebahattin çatal
sebahattin çatal

Reputation: 241

Try code and update database:

App\User::find($request->id)->tasks()->update([
    'name' => $request->title,
    'body' => $request->body
]);


return redirect('/request');

Upvotes: 1

Related Questions