L
L
lemonlimelike2018-02-05 01:56:19
Laravel
lemonlimelike, 2018-02-05 01:56:19

Why doesn't the save() method work on related models?

Did according to the documentation

public function update(Request $request, $id)
    {
        User::find($request->user_id)->roles()->save(['role_id' =>$request->role_id]);
        {
            Session::flash('store', 'Привелегия успешна добавлена!');
            return redirect()->route('users.index');
        }
    }

And there is an error 5a778f7f901ea106488032.png
Why does not work?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Kirill Nesmeyanov, 2018-02-05
@SerafimArts

Because argument 1 to Illuminate\Database\Eloquent\Realtions\BelongsToMany::save() must be an instance of Illuminate\Database\Eloquent\Model, but an array given.
Always happy to help, no thanks.

A
Alex Wells, 2018-02-05
@Alex_Wells

Made fun of the author)))
->roles()->create(

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question