Skip to content

Hide/show filter options based on user roles. #465

Closed Answered by rappasoft
dhruva81 asked this question in Q&A
Discussion options

You must be logged in to vote
public function filters(): array
{
    // Available to everyone
    $filters = [
        'type' => Filter::make('User Type')
            ->select([
                '' => 'Any',
                UserTypeEnum::admin()->value => Str::plural(UserTypeEnum::admin()->label),
                UserTypeEnum::user()->value => Str::plural(UserTypeEnum::user()->label),
            ]),
    ];

    // Available to only admins
    if (auth()->user()->isAdmin()) {
        $filters['2fa'] => Filter::make('Two Factor Authentication')
            ->select([
                '' => 'Any',
                'enabled' => 'Enabled',
                'disabled' => 'Disabled',
            ]);
    }

    return $filters;
}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@dhruva81
Comment options

Answer selected by dhruva81
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants