Skip to main content
BackpackForLaravel

All about intercepting the BackpackForLaravel create command

By November 24, 2020No Comments

How to assign a custom Role to the saved user record with BackPackForLaravel?

I was saving a user and when the user is saved, I wanted to assign a role. Here’s how I achieved it.

I created a store method that overrides the store method in CrudController the store function in my module (CrudController) was a copy of the store method inside the CrudController. I just had to add one line to add the Role by intervening the process.

1
2
3
4
// insert item in the db
$item = $this->crud->create($this->crud->getStrippedSaveRequest());
// THIS LINE
$item->assignRole('Admin');