Laravel-Backpack / PermissionManager

Admin interface for managing users, roles, permissions, using Backpack CRUD
http://backpackforlaravel.com
Other
516 stars 166 forks source link

How to add 'Select Role(s)' (dropdown) on user create/edit crud view (and get it to save)? #350

Closed gvanto closed 8 months ago

gvanto commented 8 months ago

Not a bug, but think it would be a great addition to README as this would be a very common use case (also I can't see how to do this).

I've tried the following (it adds the multiple select fine - is it possible to limit this to one select only? I only want user to have 1 role) but get an error when saving ...

protected function setupCreateOperation()
    {
        CRUD::field('name')->validationRules('required|min:4');
        CRUD::field('email')->validationRules('required|email|unique:users,email');
        CRUD::field('password')->validationRules('required');

        // https://backpackforlaravel.com/docs/6.x/crud-fields#select-1-n-relationship
        CRUD::field([
            'label' => 'Role',
            'type' => 'select_multiple',
            'name' => 'role',
            'model'     => 'Backpack\PermissionManager\app\Models\Role',
            'entity' => 'roles',
            'pivot' => true,
        ]);
    }

image

Is there additional code required to get the role(id) to save?

welcome[bot] commented 8 months ago

Hello there! Thanks for opening your first issue on this repo!

Just a heads-up: Here at Backpack we use Github Issues only for tracking bugs. Talk about new features is also acceptable. This helps a lot in keeping our focus on improving Backpack. If you issue is not a bug/feature, please help us out by closing the issue yourself and posting in the appropriate medium (see below). If you're not sure where it fits, it's ok, a community member will probably reply to help you with that.

Backpack communication mediums:

Please keep in mind Backpack offers no official / paid support. Whatever help you receive here, on Gitter, Slack or Stackoverflow is thanks to our awesome awesome community members, who give up some of their time to help their peers. If you want to join our community, just start pitching in. We take pride in being a welcoming bunch.

Thank you!

-- Justin Case The Backpack Robot

gvanto commented 8 months ago

Ah nevermind, I wasn't extending the PM controller, this fixes it. Nice work guys!

class UserCrudController extends \Backpack\PermissionManager\app\Http\Controllers\UserCrudController