Reputation: 33
Here is my code I am using, it runs fine but when I'm inside the database checking if everything went okay I get this result
Why am I getting 0 for the permission ID and Role ID?
$developer = new Role();
$developer->name = 'Test';
$view_customers = new Permission();
$view_customers->name = 'view_customers';
$view_customers->display_name = 'View Customers';
$developer->attachPermission($view_customers->id);
Upvotes: 2
Views: 1780
Reputation: 899
attachPermission()
works by model or array, if you want atach or detach by id use this
$developer->perms()->attach($view_customers->id);
Upvotes: 0
Reputation: 1589
try this
$developer = Role::where('name','=','Test')->get->first();
//if you want to attach new permission
$view_customers = new Permission();
$view_customers->name = 'view_customers';
$view_customers->display_name = 'View Customers';
//if you want to attach existing permission ex. you already have 'view_customers' in permission table
$view_customers = Permission::where('name','=','view_customers')->get->first();
$developer->attachPermission($view_customers);
Upvotes: 2