Laravel-permission: initial role to user

Created on 26 Dec 2017  路  3Comments  路  Source: spatie/laravel-permission

Hi Guys.
I have made a super-admin role from the CLI, how can I assign this role to the user that is superadmin?

No users has any permission or anything yet, I have not created a GUI for this, and i belived i could just do it from the CLI as well, but that's not the case.

Sorry for the stupid question.

Most helpful comment

php artisan tinker
$user = \App\User::find(1);

then:
From the README: https://github.com/spatie/laravel-permission#using-permissions-via-roles

$user->assignRole('writer'); ... where writer could be super-duper-admin-role or whatever the role name.

All 3 comments

php artisan tinker
$user = \App\User::find(1);

then:
From the README: https://github.com/spatie/laravel-permission#using-permissions-via-roles

$user->assignRole('writer'); ... where writer could be super-duper-admin-role or whatever the role name.

Thanks dr byte.
Actually I had tried to select the user this way: $user = App\User::where('id',1)->get();
And then it throwed an error, but your suggestion got it all to work. 馃憤

@tripex just for info, get() would return a collection of one user. You needed to have used first(). The App may also have needed a back-slaseh profix () but I'm not sure what namespace tinker runs in, so maybe not.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

notflip picture notflip  路  3Comments

dylangeorgeharbour picture dylangeorgeharbour  路  3Comments

ionesculiviucristian picture ionesculiviucristian  路  4Comments

antweny picture antweny  路  4Comments

younus93 picture younus93  路  4Comments