Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

marbobo's avatar
Level 12

filament error modal to notification or any other alternatives?

Hello,

I have a working laravel filament project in production. I wonder if theres a way to make the error modal to become a notification? because I have enable the database notification.. or if not.. is there an alternative way of doing it?? because i think showing a modal for saying "500 | Error" is quite bold for me..

1 like
2 replies
LaryAI's avatar
Level 58

To address your concern about replacing the error modal with a notification in a Laravel Filament project, you can use Laravel's built-in notification system to display error messages more subtly. Here's a step-by-step guide to achieve this:

  1. Create a Custom Exception Handler: Override the render method in your App\Exceptions\Handler class to handle exceptions and send notifications.

    namespace App\Exceptions;
    
    use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
    use Illuminate\Support\Facades\Notification;
    use App\Notifications\ErrorNotification;
    use Throwable;
    
    class Handler extends ExceptionHandler
    {
        public function render($request, Throwable $exception)
        {
            // Check if the request expects a JSON response
            if ($request->expectsJson()) {
                // Send a notification
                Notification::route('mail', '[email protected]')
                    ->notify(new ErrorNotification($exception));
    
                // Return a JSON response
                return response()->json(['error' => 'Something went wrong.'], 500);
            }
    
            // For non-JSON requests, you can redirect or show a custom error page
            return parent::render($request, $exception);
        }
    }
    
  2. Create a Notification Class: Generate a notification class to handle the error notification.

    php artisan make:notification ErrorNotification
    

    Then, update the generated ErrorNotification class:

  3. Enable Database Notifications: If you want to store notifications in the database, ensure you have the necessary setup:

    php artisan notifications:table
    php artisan migrate
    

    Update the via method in the ErrorNotification class to include the database channel:

    public function via($notifiable)
    {
        return ['mail', 'database'];
    }
    
    public function toDatabase($notifiable)
    {
        return [
            'message' => 'An error occurred: ' . $this->exception->getMessage(),
            'file' => $this->exception->getFile(),
            'line' => $this->exception->getLine(),
        ];
    }
    
  4. Display Notifications in Filament: To display notifications in your Filament dashboard, you can use the built-in notification system. For example, you can use the Notification facade to display a notification when an error occurs.

    use Filament\Notifications\Notification;
    
    Notification::make()
        ->title('Error')
        ->body('Something went wrong.')
        ->danger()
        ->send();
    

By following these steps, you can replace the error modal with a more subtle notification system in your Laravel Filament project. This approach ensures that users are informed of errors without the abruptness of a modal dialog.

Please or to participate in this conversation.