F
Filamentβ€’9mo ago
waleedGRT

Validation Error Display Issue in Ban Middleware Implementation

I am using a ban middleware to check if a user is banned or not. Everything is functioning correctly, but I'm experiencing an issue where validation errors are not being showing. Middlewire Code
public function handle(Request $request, Closure $next): Response
{

if (auth()->check() && (auth()->user()->status == 0)) {
Auth::logout();

$request->session()->invalidate();

$request->session()->regenerateToken();

return redirect()->route('filament.admin.auth.login')->withErrors(['ban' => 'Your account has been suspended.']);
}
return $next($request);
}
public function handle(Request $request, Closure $next): Response
{

if (auth()->check() && (auth()->user()->status == 0)) {
Auth::logout();

$request->session()->invalidate();

$request->session()->regenerateToken();

return redirect()->route('filament.admin.auth.login')->withErrors(['ban' => 'Your account has been suspended.']);
}
return $next($request);
}
Custom blade for login page
<x-filament-panels::page.simple>
{{ \Filament\Support\Facades\FilamentView::renderHook('panels::auth.login.form.before') }}

<x-filament-panels::form wire:submit="authenticate">
{{ $this->form }}
<x-filament-panels::form.actions :actions="$this->getCachedFormActions()" :full-width="$this->hasFullWidthFormActions()" />
</x-filament-panels::form>

@env('local')
<x-login-link redirect-url="{{ route('filament.admin.pages.dashboard') }}" />
@endenv

@error('ban') // error message
<span class="error">{{ $message }}</span>
@enderror

{{ \Filament\Support\Facades\FilamentView::renderHook('panels::auth.login.form.after') }}
</x-filament-panels::page.simple>
<x-filament-panels::page.simple>
{{ \Filament\Support\Facades\FilamentView::renderHook('panels::auth.login.form.before') }}

<x-filament-panels::form wire:submit="authenticate">
{{ $this->form }}
<x-filament-panels::form.actions :actions="$this->getCachedFormActions()" :full-width="$this->hasFullWidthFormActions()" />
</x-filament-panels::form>

@env('local')
<x-login-link redirect-url="{{ route('filament.admin.pages.dashboard') }}" />
@endenv

@error('ban') // error message
<span class="error">{{ $message }}</span>
@enderror

{{ \Filament\Support\Facades\FilamentView::renderHook('panels::auth.login.form.after') }}
</x-filament-panels::page.simple>
No description
1 Reply
waleedGRT
waleedGRTβ€’9mo ago
🧐 Using this strategy in the user model, I was able to resolve the problem.
public function canAccessPanel(Panel $panel): bool
{
if ($panel->getId() === 'admin') {
return $this->is_admin && $this->status;
}
return true;
}
public function canAccessPanel(Panel $panel): bool
{
if ($panel->getId() === 'admin') {
return $this->is_admin && $this->status;
}
return true;
}