PHPackages                             codezero/laravel-flash - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Queues &amp; Workers](/categories/queues)
4. /
5. codezero/laravel-flash

ActiveLibrary[Queues &amp; Workers](/categories/queues)

codezero/laravel-flash
======================

Clean flash message system for Laravel.

3.0.0(2y ago)3267MITPHPPHP ^8.1CI failing

Since May 15Pushed 2y ago3 watchersCompare

[ Source](https://github.com/codezero-be/laravel-flash)[ Packagist](https://packagist.org/packages/codezero/laravel-flash)[ Fund](https://paypal.me/ivanvermeyen)[ Fund](https://ko-fi.com/ivanvermeyen)[ RSS](/packages/codezero-laravel-flash/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (10)Dependencies (4)Versions (11)Used By (0)

Flash Notifications for Laravel
===============================

[](#flash-notifications-for-laravel)

[![GitHub release](https://camo.githubusercontent.com/fd185930eac7689767bc136d7772a639f1dcf33380371e8369ebc2e4841ac024/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f636f64657a65726f2d62652f6c61726176656c2d666c6173682e7376673f7374796c653d666c61742d737175617265)](https://github.com/codezero-be/laravel-flash/releases)[![Laravel](https://camo.githubusercontent.com/6b439d6929b4963e5e873cdf2ac7d587f60c8730be8590e1ae384897cebc6369/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c61726176656c2d31312d7265643f7374796c653d666c61742d737175617265266c6f676f3d6c61726176656c266c6f676f436f6c6f723d7768697465)](https://laravel.com)[![License](https://camo.githubusercontent.com/51b02691e4d96f9fff3238bd3034b9afe98bee477a7bd9861ab81fde5dc9ddee/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f636f64657a65726f2f6c61726176656c2d666c6173682e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/794f9c029aa81ac878615a494b97b86ec9c1ac20a4c5e93cd1ec64d8e6ab23c5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f636f64657a65726f2d62652f6c61726176656c2d666c6173682f72756e2d74657374732e796d6c3f7374796c653d666c61742d737175617265266c6f676f3d676974687562266c6f676f436f6c6f723d7768697465266c6162656c3d7465737473)](https://github.com/codezero-be/laravel-flash/actions)[![Code Coverage](https://camo.githubusercontent.com/fd366d9812df30e0fe617852ce59215d8aeaaaf05253c44091b3ccc0cb8ba5d8/68747470733a2f2f696d672e736869656c64732e696f2f636f646163792f636f7665726167652f32326435306264323738323534306262383036663537363936366135663564352f6d61737465723f7374796c653d666c61742d737175617265)](https://app.codacy.com/gh/codezero-be/laravel-flash)[![Code Quality](https://camo.githubusercontent.com/cca86da11ba773ed23ab0237b28e88a4715da77114e2d7e29f03f8ec3a106ec0/68747470733a2f2f696d672e736869656c64732e696f2f636f646163792f67726164652f32326435306264323738323534306262383036663537363936366135663564352f6d61737465723f7374796c653d666c61742d737175617265)](https://app.codacy.com/gh/codezero-be/laravel-flash)[![Total Downloads](https://camo.githubusercontent.com/491acf1b834756f761c98b79ade99bec81e6faf6d910afd6a681d16daa5196a8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636f64657a65726f2f6c61726176656c2d666c6173682e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/codezero/laravel-flash)

[![ko-fi](https://camo.githubusercontent.com/1fedf764fa06114b797ee53e7506df10880abed6766f854202d758df1707969d/68747470733a2f2f7777772e6b6f2d66692e636f6d2f696d672f676974687562627574746f6e5f736d2e737667)](https://ko-fi.com/R6R3UQ8V)

#### Flash messages to the session with [Laravel](http://laravel.com/).

[](#flash-messages-to-the-session-with-laravel)

🧩 Features
----------

[](#-features)

- Flash multiple messages.
- Use built in notification levels (success, error, ...) or imagine your own.

✅ Requirements
--------------

[](#-requirements)

- PHP &gt;= 8.1
- Laravel &gt;= 10.0

📦 Install
---------

[](#-install)

```
composer require codezero/laravel-flash
```

> Laravel will automatically register the ServiceProvider.

🛠 Usage
-------

[](#-usage)

Somewhere in your views, include the flash notifications partial:

```
@include('flash::notifications')
```

Then you can flash a message to the session in your controllers.

```
flash()->success('Update succeeded!');
```

> You can also use the facade `\CodeZero\Flash\Facades\Flash` instead of the `flash()` helper.

The message will be displayed once on the next page load.

🚨 Notification Levels
---------------------

[](#-notification-levels)

You can use the built in notification levels:

```
flash()->info('info message');
flash()->success('success message');
flash()->warning('warning message');
flash()->error('error message');
```

Or you can specify a custom level:

```
flash()->notification('message', 'level');
```

🔖 Rendering Notifications
-------------------------

[](#-rendering-notifications)

### Customize the notification views

[](#customize-the-notification-views)

If you want to customize the templates, you can publish the views:

```
php artisan vendor:publish --provider="CodeZero\Flash\FlashServiceProvider" --tag="views"
```

You will find the views in `resources/views/vendor/flash`.

### Default views for built in notification levels

[](#default-views-for-built-in-notification-levels)

A notification will be rendered using a view file which name corresponds with the notification level.

So `flash()->success('message')` will load a `success.blade.php` view file.

These views live in `resources/views/vendor/flash/notifications`.

### Default view for custom notification levels

[](#default-view-for-custom-notification-levels)

If no corresponding file can be found in the package's view folder, then the `default.blade.php` view file will be used.

So `flash()->notification('message', 'custom')` will load the `default.blade.php` view file.

This view lives in `resources/views/vendor/flash/notifications`.

### Add views for custom notification levels

[](#add-views-for-custom-notification-levels)

To add view files for custom levels, create them in `resources/views/vendor/flash/notifications`.

### Override default notification views

[](#override-default-notification-views)

You can override the view file to be used when you flash a notification:

```
// use 'resources/views/custom.blade.php' instead of
// 'resources/views/vendor/flash/notifications/success.blade.php'
flash()->success('message')->setView('custom');
```

The specified view name is relative to your app's view folder `resources/views`.

### Access notification values in a view

[](#access-notification-values-in-a-view)

Notification views will have a `$notification` variable which is an instance of `\CodeZero\Flash\Notification`.

This gives you access to:

```
{{ $notification->message }}
{{ $notification->level }}
```

🔧 Create Your Own Custom Flash Class
------------------------------------

[](#-create-your-own-custom-flash-class)

If you don't want to use the built in notification levels and want to create your own, you can extend the `\CodeZero\Flash\BaseFlash` class.

```
