On laravel 10 / filamentphp 3 site with multi tenancy I made custom register page with additive columns and code in app/Providers/Filament/AppPanelProvider.php :
<?php
namespace App\Providers\Filament;
use App\Filament\App\Pages\Auth\Register; // I define custom Register page
use App\Filament\App\Pages\Tenancy\RegisterBranch;
use App\Models\Branch;
use Filament\PanelProvider;
...
class AppPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
return $panel
->default()
->plugins([ ])
->id('app')
->path('app')
->login()
->profile()
->registration(Register::class)
I define custom Register page as I need with creating User model to add 2 additive models and in app/Filament/Pages/Auth/MyCustomRegister.php I call aditive event :
<?php
namespace App\Filament\Pages\Auth;
use App\Events\UserRegisteredEvent;
use DanHarrin\LivewireRateLimiting\Exceptions\TooManyRequestsException;
use Filament\Facades\Filament;
use Filament\Forms\Form;
use Filament\Http\Responses\Auth\Contracts\RegistrationResponse;
use Filament\Notifications\Notification;
use Filament\Pages\Auth\Register;
/**
* @property Form $form
*/
class MyCustomRegister extends Register // SimplePage
{
public function register(): ?RegistrationResponse
{
try {
$this->rateLimit(2);
} catch (TooManyRequestsException $exception) {
Notification::make()
->title(__('filament-panels::pages/auth/register.notifications.throttled.title', [
'seconds' => $exception->secondsUntilAvailable,
'minutes' => ceil($exception->secondsUntilAvailable / 60),
]))
->body(array_key_exists('body', __('filament-panels::pages/auth/register.notifications.throttled') ?: []) ? __('filament-panels::pages/auth/register.notifications.throttled.body', [
'seconds' => $exception->secondsUntilAvailable,
'minutes' => ceil($exception->secondsUntilAvailable / 60),
]) : null)
->danger()
->send();
return null;
}
$data = $this->form->getState();
$user = $this->getUserModel()::create($data);
$this->sendEmailVerificationNotification($user);
Filament::auth()->login($user);
session()->regenerate();
$request= request();
UserRegisteredEvent::dispatch($user, $this->data); // I call event to add more models
// if to uncomment line below I got error that RegistrationResponse must be returned
// return redirect()->route('filament.app.auth.profile')->with('message', $user->name . ' was registered !');
return app(RegistrationResponse::class);
}
}
But page for entering of new tenant "app/new" is opened. I routes I found lines:
GET|HEAD app/new ........................................................................................................... filament.app.tenant.registration › App\Filament\App\Pages\Tenancy\RegisterBranch
GET|HEAD app/profile ............................................................................................................................... filament.app.auth.profile › Filament\Pages › EditProfile
to move to profile page
In filamentphp docs I did not find any RegistrationResponse reference, which is in vendor/filament/filament/src/Http/Responses/Auth/Contracts/RegistrationResponse.php file :
namespace Filament\Http\Responses\Auth\Contracts;
use Illuminate\Contracts\Support\Responsable;
interface RegistrationResponse extends Responsable
{
}
Have I declare RegistrationResponse with redirect to 'filament.app.auth.profile' ? How ? Or in some other way ?
"laravel/framework": "^10.28.0",
"filament/filament": "^3.0-stable",
DETAILS BLOCK : With command
php artisan vendor:publish --tag=filament-config
I created file config/filament.php:
<?php
return [
/*
|--------------------------------------------------------------------------
| Broadcasting
|--------------------------------------------------------------------------
|
| By uncommenting the Laravel Echo configuration, you may connect Filament
| to any Pusher-compatible websockets server.
|
| This will allow your users to receive real-time notifications.
|
*/
'broadcasting' => [
// 'echo' => [
// 'broadcaster' => 'pusher',
// 'key' => env('VITE_PUSHER_APP_KEY'),
// 'cluster' => env('VITE_PUSHER_APP_CLUSTER'),
// 'wsHost' => env('VITE_PUSHER_HOST'),
// 'wsPort' => env('VITE_PUSHER_PORT'),
// 'wssPort' => env('VITE_PUSHER_PORT'),
// 'authEndpoint' => '/api/v1/broadcasting/auth',
// 'disableStats' => true,
// 'encrypted' => true,
// ],
],
/*
|--------------------------------------------------------------------------
| Default Filesystem Disk
|--------------------------------------------------------------------------
|
| This is the storage disk Filament will use to put media. You may use any
| of the disks defined in the `config/filesystems.php`.
|
*/
'default_filesystem_disk' => env('FILAMENT_FILESYSTEM_DISK', 'public'),
/*
|--------------------------------------------------------------------------
| Assets Path
|--------------------------------------------------------------------------
|
| This is the directory where Filament's assets will be published to. It
| is relative to the `public` directory of your Laravel application.
|
| After changing the path, you should run `php artisan filament:assets`.
|
*/
'assets_path' => null,
/*
|--------------------------------------------------------------------------
| Livewire Loading Delay
|--------------------------------------------------------------------------
|
| This sets the delay before loading indicators appear.
|
| Setting this to 'none' makes indicators appear immediately, which can be
| desirable for high-latency connections. Setting it to 'default' applies
| Livewire's standard 200ms delay.
|
*/
'livewire_loading_delay' => 'default',
];
which have the only commented "authEndpoint" parameter. Looking at the branch I tried to add lines :
'auth' => [
'pages' => [
// 'login' => \Your\Custom\LoginLogic::class,
'register' => \Your\Custom\RegisterLogic::class,
],
],
What must in in RegisterLogic - as I need to relpace After Register method with my code ?
Thanks in advance !
For Overriding Register Page, We Need to Create a New Page as Below
php artisan make:filament-page Auth/Register
The Register Page Should be then Modifies as Below:
app/Filament/Pages/Auth/Register.php
use Filament\Pages\Auth\Register as BaseRegister;
class Register extends BaseRegister {}
Then in 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)
//....
}
}
Now You Can Add your Custom Fields Here as in Below Example. Everything will be handled by the Filament unless you are using custom Database model to For Registration For that you can Follow up This Link
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Component;
class Register extends BaseRegister
{
protected function getForms(): array
{
return [
'form' => $this->form(
$this->makeForm()
->schema([
$this->getNameFormComponent(),
$this->getEmailFormComponent(),
$this->getPasswordFormComponent(),
$this->getPasswordConfirmationFormComponent(),
$this->getRoleFormComponent(),
])
->statePath('data'),
),
];
}
protected function getRoleFormComponent(): Component
{
return Select::make('role')
->options([
'buyer' => 'Buyer',
'seller' => 'Seller',
])
->default('buyer')
->required();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With