0

I am using spatie to assign and give permissions to user roles.

I need to update the role_id column in model_has_roles table.

I tried using eloquent but unfortunately there is no model for the tables created under the spatie migrations.

Right now I am using the below function to update:

    $user_role = DB::table('model_has_roles')
        ->where('model_id', '=', $request->userid)  
        ->select('model_has_roles.*')
        ->get();

    $user_role->role_id = $request->userid;
    $user_role->save();

But this says that "Method save does not exist"

Any advice on how to update the database column?

3
  • DB::table()->get() returns stdClass objects, they don't have methods on them. Did you read the docs here: github.com/spatie/…? Commented Oct 25, 2018 at 12:01
  • How can I write the update query then? Commented Oct 25, 2018 at 12:02
  • 1
    Write an update query... If you don't use Eloquent Models, you won't have access to the ORM methods. Might want to make sure you read through the Laravel docs and the spatie permission docs so you understand more about what you're doing. Commented Oct 25, 2018 at 12:03

1 Answer 1

2

As there are no Eloquent models, this cannot use the ORM methods as @Devon said in the comments. I used the below update query and it worked fine.

DB::table('model_has_roles')
->where('model_id', $request->userid)
->update(['role_id' =>  $request->editusertype]);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.