PHPackages                             lukebro/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. lukebro/flash

ActiveLibrary

lukebro/flash
=============

Magical flash notifications in Laravel 5.\*

v0.4.0(6y ago)85512MITPHPPHP &gt;=5.6

Since Aug 17Pushed 6y ago1 watchersCompare

[ Source](https://github.com/lukebro/flash)[ Packagist](https://packagist.org/packages/lukebro/flash)[ RSS](/packages/lukebro-flash/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (3)Versions (9)Used By (0)

Magical flash notifications in Laravel 5.\* &amp; 6.\*
======================================================

[](#magical-flash-notifications-in-laravel-5--6)

[![Build Status](https://camo.githubusercontent.com/a048c76569692ad0108ea6311e6600c66e82ddae3928018cc23be35a2ddcf915/68747470733a2f2f7472617669732d63692e6f72672f6c756b6562726f2f666c6173682e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/lukebro/flash)

A simple magical API for flashing notifications to a session inside Laravel 5.\*.

```
flash()->success('Signed in successfully.');
```

Installation
------------

[](#installation)

Requires [PHP 5.5.9](http://php.net), [Laravel 5.\* &amp; 6.\*](http://github.com/laravel/laravel) and [Composer](http://getcomposer.org).

Add the following line to the require block of your `composer.json` file:

```
	"lukebro/flash": "~0.3"
```

Run `composer install` or `composer update`.

Include the service provider within `\config\app.php`:

```
	'providers': [
			Lukebro\Flash\FlashServiceProvider::class,
	];
```

Add the facade alias at the bottom of the same file:

```
	'aliases' => [
	    'Flash' => Lukebro\Flash\FlashFacade::class
	];
```

Usage
-----

[](#usage)

### Flashing notifications

[](#flashing-notifications)

Before redirecting, flash a message to the screen:

```
flash()->warning('Max file size is 5MB.');
```

Inside your view's you have access to a `flash()->level` and `flash()->message` attribute.

The `level` attribute is the name of the function you called, which could be anything. The `message` attribute is the string you passed into the magical function.

So for the example above, `flash()->level` and `flash()->message` would equal `warning` and `Max file size is 5MB.` respectively.

A flash message is not required, calling just a method will result in just the level being flashed.

You also have access to a `Flash` facade which you could use in place of the `flash()` helper function.

### Flashing multiple notifications

[](#flashing-multiple-notifications)

You can chain your flashes like so:

```
flash()->warning('Max file size is 5MB.')
	   ->warning('Username is required.')
	   ->danger('There was an error validating your information.');
```

Inside your views `flash()->level` and `flash()->message` attributes will return the level and message of the **last** message flashed. To get a `Collection` of all messages flashed you have access to `flash()->all()`.

So for example to iterate through all messages flashed inside your view:

```
@foreach (flash()->all() as $flash)
	{{ $flash->message }}
@endforeach
```

`flash()->all()` returns Laravel's Collection class, so you have access to all methods Collection contains such as `groupBy()`, `chunk()`, `toJson()`, etc. It could also just be treated as an array.

### Detecting flash notifications

[](#detecting-flash-notifications)

To detect if any flash messages exist in the session, use `flash()->exists()`.

If you want to detect a specific level, use the `has()` method. E.g. `flash()->has('error')`. This works for single or multiple flashed messages.

It's best use to detect if a certain level was flashed and then display only the notifications of that level using the `get()` method.

```
@if (flash()->has('error'))

		@foreach (flash()->get('error') as $flash)
			{{ $flash->message }}
		@endforeach

@endif
```

### Reflashing notifications

[](#reflashing-notifications)

To reflash notification or all notifications to the next request use the function `again()`.

```
flash()->again();
```

You're able to flash more messages before, or after calling the `flash()->again()` method.

Helper function
---------------

[](#helper-function)

You may also just pass a level and a message into the `flash()` helper function.

```
flash('error', 'There was an error processing your request.');
```

Single vs Multiple Flashes
--------------------------

[](#single-vs-multiple-flashes)

Depending on what your application needs, set up your views to display flashes using a loop or just the attributes. For example if your application is only going to flash one notification at a time, using `flash()->level` and `flash()->message` directly in your views is fine.

However, if your application will flash multiple notifications it's best to set up a `foreach` loop and iterate over `flash()->all()`. Again you'll still have direct access to the `flash()->level` and `flash()->message` attributes even if multiple notifications were flashed, but there values will be of the last notification flashed.

Examples
--------

[](#examples)

Below are some basic blade templates/examples.

Single flash example

```
@if (flash()->exists())

		{{ flash()->message }}

@endif
```

Multiple flash example

```
@if (flash()->exists())
	@foreach (flash()->all() as $flash)

			{{ $flash->message }}

	@endforeach
@endif
```

Detecting a specific level

```
@if (flash()->has('success'))

		launchFireworks();

@endif
```

Detecting a specific level and displaying multiple messages

```
@if (flash()->has('error'))

		@foreach (flash()->get('error') as $flash)
			{{ $flash->message }}
		@endforeach

@endif
```

Details
-------

[](#details)

The data is stored inside Laravel's session under the key `flashes` in the following format:

```
[
	'flashes' => [
		['level' => '', 'message' => ],
		['level' => '', 'message' => ]
	]
]
```

`flash()->all()` returns a Collection of Flash object. A flash object contains two attributes: `level`, and `message` which are publicly accessable. You may also access them via array syntax as such: `$flash['level']` and `$flash['message']`. A `Flash` object has a `toArray()` and `toJson()` method.

Contributions
-------------

[](#contributions)

Feel free to [create an issue](https://github.com/lukebro/flash/issues) with a feature request or bug report. If you would rather implement the feature or fix the bug yourself, create a pull request. I'm not sure how far I want to take this package, as of right now I'm pretty happy where it stands.

Contributions can be made to the documentation as well, not just code. If you think you can explain the API better than I can, please do and I'll be happy to merge it in.

I'd love to hear your feedback in how the package feels and what you don't like about it.

Credits
-------

[](#credits)

The inspiration for this extremely small package comes from Jeffrey Way's Laracast video: [Elegant Flash Messaging](https://laracasts.com/series/build-project-flyer-with-me/episodes/9). Definitely check it out. Jeffrey mentions that you could write the API in a "magical" way, so I thought it would be cool to implement.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 94.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~211 days

Recently: every ~363 days

Total

8

Last Release

2446d ago

PHP version history (3 changes)v0.1.0PHP &gt;5.5.9

v0.2.2PHP &gt;=5.5.9

v0.2.4PHP &gt;=5.6

### Community

Maintainers

![](https://www.gravatar.com/avatar/3a6104cd58db0385cae520b0f2cd874a47fb8e839fcaada1d9dca449c28869a5?d=identicon)[lukebro](/maintainers/lukebro)

---

Top Contributors

[![lukebro](https://avatars.githubusercontent.com/u/2486195?v=4)](https://github.com/lukebro "lukebro (32 commits)")[![mewebstudio](https://avatars.githubusercontent.com/u/2125733?v=4)](https://github.com/mewebstudio "mewebstudio (2 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/lukebro-flash/health.svg)

```
[![Health](https://phpackages.com/badges/lukebro-flash/health.svg)](https://phpackages.com/packages/lukebro-flash)
```

###  Alternatives

[fumeapp/modeltyper

Generate TypeScript interfaces from Laravel Models

196277.9k](/packages/fumeapp-modeltyper)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
