Filamentphp filter record using tabs

Filamentphp filter record using tabs

Posted on:March 2, 2024 at 01:22 PM

Imagine that I have a list of users. Some of them have verified email (email_verified_at) and some of them are not. Today I will show you the process to filter user by email verified and display in the tab.

How to do that?

In your ListUsers.php page, add getTabs() method like this:

public function getTabs(): array
{
    return [
        'all' => Tab::make('All Users'),

        'verified' => Tab::make('Verified Users')
            ->modifyQueryUsing(function ($query) {
                $query->whereNotNull('email_verified_at');
            }),

        'unverified' => Tab::make('Unverified Users')
            ->modifyQueryUsing(function ($query) {
                $query->whereNull('email_verified_at');
            }),
    ];
}

Now in your /users/ url, you should see tabs that allows you to filter users.

Thanks.