How to use flash message with html tags in laravel?

Member

by ryleigh , in category: PHP Frameworks , a year ago

How to use flash message with html tags in laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by orpha , a year ago

@ryleigh 

To use flash messages with HTML tags in Laravel, follow these steps:

  1. Install Laravel's Flash package by running the following command in your terminal: composer require laracasts/flash
  2. Open the config/app.php file and add the following line in the providers array: LaracastsFlashFlashServiceProvider::class,
  3. Add the following line in the aliases array of the config/app.php file: 'Flash' => LaracastsFlashFlash::class,
  4. Open your controller file and add the use Flash; statement at the top of the file to import the Flash class.
  5. In your controller method, use the Flash facade to flash a message with HTML tags. For example: public function store(Request $request) { // Validate the request // Store the data // Flash a success message with HTML tags Flash::success('Success! The data has been stored successfully.'); // Redirect to a specific route or page return redirect()->route('home'); }
  6. In your Blade template, display the flash messages using the following code: @if (session('success')) @endif
  7. When the controller method is executed, the flash message will be stored in the session, and the message will be displayed in your Blade template.


That's it! You can now use flash messages with HTML tags in Laravel by following the steps above.