Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter options for role select field #159

Open
daniyal-pl opened this issue May 5, 2021 · 1 comment
Open

Filter options for role select field #159

daniyal-pl opened this issue May 5, 2021 · 1 comment

Comments

@daniyal-pl
Copy link

daniyal-pl commented May 5, 2021

How can I filter the options coming in the role select field? For example, I have two roles created but I only want to show a single role option based on a condition in the select field?

RoleSelect::make('Role', 'roles'),

This is the code that is getting all the roles. I've tried many things but none has done the work.

The same goes for the permissions. how can I show only some selected permission based on a condition?

code for permissions:

PermissionBooleanGroup::make('Permissions'),

Any help would be highly appreciated. Thanks

@bzarzuela
Copy link

Something like this will help.

bzarzuela@15b2a4f

The way I use it on my project is like this. On my seeder, I have 3 roles including the Manager but I do not want the UI to show the Manager.

RoleBooleanGroup::make('Roles')
                ->withOptions([
                    'Agent' => 'Agent',
                    'Supervisor' => 'Supervisor',
                ]),

Technically this still is subject for manipulation by the user just by altering the request payload, maybe I'll add more protection in a future PR, but for something like 5 minutes of effort, this is worth it.

Easiest way is to just extend the RoleBooleanGroup class to inject a new public withOptions() method.

<?php


namespace App\Nova\Fields;


class RoleBooleanGroup extends \Vyuldashev\NovaPermission\RoleBooleanGroup
{
    public function withOptions(array $options): self
    {
        $this->options($options);

        return $this;
    }
}

This could be an alternative to #137

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants