Laravel-Backpack / PermissionManager

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

htmlspecialchars(): Argument #1 ($string) must be of type string, Closure given #362

Closed fardeen7337 closed 2 months ago

fardeen7337 commented 2 months ago

Hello,

I'm working on a Laravel project using Backpack and the Backpack PermissionManager package. I'm encountering a couple of issues related to field configurations in Backpack.

I can't do changing in the Roles table because it's access from vendor folder

checklist_dependency Field: I need to filter roles to show only specific ones (e.g., roles with the name != 'super admin')

[
                // two interconnected entities
                'label' => trans('backpack::permissionmanager.user_role_permission'),
                'field_unique_name' => 'user_role_permission',
                'type' => 'checklist_dependency',
                'name' => 'roles,permissions',
                'subfields' => [
                    'primary' => [

                        'label' => trans('backpack::permissionmanager.roles'),
                        'name' => 'roles', // the method that defines the relationship in your Model
                        'entity' => 'roles', // the method that defines the relationship in your Model
                        'entity_secondary' => 'permissions', // the method that defines the relationship in your Model
                        'attribute' => 'name', // foreign key attribute that is shown to user
                        'model' => config('permission.models.role'), // foreign key model
                        'pivot' => true, // on create&update, do you need to add/delete pivot table entries?]
                        'number_columns' => 3, //can be 1,2,3,4,6
                        'options' => function ($query){
                            $query->where('name','!=' ,'super admin');
                        },

                    ],
                    'secondary' => [
                        'label' => mb_ucfirst(trans('backpack::permissionmanager.permission_plural')),
                        'name' => 'permissions', // the method that defines the relationship in your Model
                        'entity' => 'permissions', // the method that defines the relationship in your Model
                        'entity_primary' => 'roles', // the method that defines the relationship in your Model
                        'attribute' => 'name', // foreign key attribute that is shown to user
                        'model' => config('permission.models.permission'), // foreign key model
                        'pivot' => true, // on create&update, do you need to add/delete pivot table entries?]
                        'number_columns' => 3, //can be 1,2,3,4,6
                    ],
                ],
            ],

I have added this line but getting error htmlspecialchars(): Argument #1 ($string) must be of type string, Closure given

  'options' => function ($query){
                            $query->where('name','!=' ,'super admin');
                        },
welcome[bot] commented 2 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

pxpm commented 2 months ago

Thanks for the report @fardeen7337

There was no way to filter out the checklist_dependency options you are right, and I've need this myself in the past 🫨

I've added the ability to customize the query of the checklist_dependency inputs in https://github.com/Laravel-Backpack/CRUD/pull/5650 and will tag a new version with the changes later today or tomorrow.

Cheers