Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

passing the role name isn't eloquent .

you can pass an array of id's passing an array or objects with internally takes all the id's and passes again,

you can also pass a key value array of ids and their pivot data too

0

Are there any special functions or methods I should know about that help me get the ID by using the role name?

0
$role = App\Role::where('name', 'admin')->first();

$user->roles()->sync($role->id)
0

LaurentMeganck said:

$role = App\Role::where('name', 'admin')->first();

$user->roles()->sync($role->id)

Thanks. I figured that could be done, but was wondering if there was a one liner solution.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

skunkbad skunkbad Joined 23 Jun 2016

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.