Skip to content

Instantly share code, notes, and snippets.

@dillingham
Last active February 4, 2019 04:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dillingham/5df970e437d6c1c15a0b245bf4034816 to your computer and use it in GitHub Desktop.
Save dillingham/5df970e437d6c1c15a0b245bf4034816 to your computer and use it in GitHub Desktop.
Bulk assign permissions to role

Bulk assign permissions to role

Bulk assign permissions to role

Make the following 2 actions

AttachRole

public function handle(ActionFields $fields, Collection $models)
{
    foreach ($models as $model) {
        $model->roles()->syncWithoutDetaching($fields->role);
    }
}

public function fields()
{
    return [
        Select::make('Role')->options(
            \App\Role::all()->pluck('id', 'name')->flip()
        )->rules('required')
    ];
}

DetachRole

public function handle(ActionFields $fields, Collection $models)
{
    foreach ($models as $model) {
        $model->roles()->detach($fields->role);
    }
}

public function fields()
{
    return [
        Select::make('Role')->options(
            \App\Role::all()->pluck('id', 'name')->flip()
        )->rules('required')
    ];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment