Filament: Roles: Broker vs Investor in Single Panel

Sometimes, a system can have multiple roles. But how do we add a Registration form where a user selects his Role? And how do we hide/show resources based on that role?

FilamentExamples ThumbBase (27)

Get the Source Code:

How it works

In the Panel Provider we enable registration and pass an action as our own custom registration page.

app/Providers/Filament/AdminPanelProvider.php:

use App\Filament\Pages\Auth\Register;
 
class AdminPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
return $panel
->default()
->id('admin')
->path('admin')
->login()
->registration(Register::class)
// ...
}
}

The registration page must extend the registration page from the Filament. In the register page, we add a radio select field for the role and set the default role to the Broker.

App/Filament/Pages/Auth/Register.php:

use App\Models\Role;
use Filament\Forms\Form;
use Filament\Forms\Components\Radio;
use Filament\Forms\Components\Component;
use Filament\Pages\Auth\Register as BaseRegister;
 
class Register extends BaseRegister
{
public function form(Form $form): Form
{
return $form
->schema([
// ....

We also have an example of how to do this using Multiple Panels

The FULL tutorial is available after the purchase: in the Readme file of the official repository you would get invited to.
Get the Source Code: All 51 Premium Examples for $99 Only Project Examples for $59