truthzeeker
truthzeeker
FFilament
Created by truthzeeker on 8/19/2024 in #❓┊help
Can't save relationship on create
Nevermind, I overridden the mount method on my Create page. So dumb. 😄
4 replies
FFilament
Created by Bryan on 7/29/2024 in #❓┊help
Filament Shield Have a Default Role
If you have many roles and have a specific user role for that panel, you need to extend the Register class and assign it to your panel, then override the register method and add your role assignment.
...
use Filament\Pages\Auth\Register as BaseRegister;

class RegisterPage extends BaseRegister
{

// Override the register method
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);

event(new \Filament\Events\Auth\Registered($user));

$user->assignRole('your role'); // assign role here

$this->sendEmailVerificationNotification($user);

Filament::auth()->login($user);

session()->regenerate();

return app(RegistrationResponse::class);
}
}
...
use Filament\Pages\Auth\Register as BaseRegister;

class RegisterPage extends BaseRegister
{

// Override the register method
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);

event(new \Filament\Events\Auth\Registered($user));

$user->assignRole('your role'); // assign role here

$this->sendEmailVerificationNotification($user);

Filament::auth()->login($user);

session()->regenerate();

return app(RegistrationResponse::class);
}
}
And in your panel
->registration(RegisterPage::class)
->registration(RegisterPage::class)
Let me know if it works for you.
11 replies