Download the PHP package leeovery/flasher without Composer
On this page you can find all versions of the php package leeovery/flasher. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download leeovery/flasher
More information about leeovery/flasher
Files in leeovery/flasher
Package flasher
Short Description A Laravel package to flash 1 or more messages to session, with the ability to override previous or future messages, and to cap messages so they only appear once per session, hour, day etc.
License MIT
Homepage https://github.com/leeovery/flasher
Informations about the package flasher
Flasher
A Laravel package (>=5.3) to flash 1 or more messages to session, with the ability to override previous or future messages, and to cap messages so they only appear once per session, hour, day etc.
Can be used with other frameworks with some edits but comes setup for Laravel sessions and cache.
Install
Via Composer
After adding the package, add the ServiceProvider to the providers array in config/app.php
You can also publish the config file and view file to make any adjustments as needed:
The View
A simple Vue / Semantic-UI implementation has been included as the view, but you can publish and edit the blade file as needed.
To use the Vue Alert component copy it to your own project, then import
it into your bootstrap js file, and then setup the component with Vue:
You can also optionally publish the blade file for the flash message output and customise as required:
Usage
The simplest implementation is just to use the flasher helper function. If you pass a message to the function it'll just output an info message to the session as a flash message, to be shown on the next request.
If you want to show different types of messages you can do the following:
You can optionally pass a title too:
Flash this request
Sometimes, especially in middleware, you want to flash a message but show it in the this request, not the next request. You can do that by passing in the now() method to the chain:
Overriding messages
If you want to flash a message (either for this request using now(), or the next request) but want to ensure its the only message flashed you can include the override method, which will wipe out any past or future flash messages during the request cycle:
If you only want to override messages of the same type, you can pass false as the 1st parameter to the override method. In the above example, it'll mean only info messages will be overridden, but any other type of flash message will be permitted.
If you pass false as the 2nd parameter to the override method, this will allow you to only override previous messages, but allow any future messages that might flash after this one. This can be useful in some cases.
Capping messages
You can use the capping methods to control how often a flash message is shown. For example, if you want to remind a user to complete their profile once every session you can do the following:
This message will only flash once per session. Meaning when they login, they will see the message. On the next request it will not show. But if they logout (or are logged out automatically), they will see it again when they next login.
There are other types of caps you can use for other scenarios.
As you can see, you can pass an integer to the time-based methods, and this does what you'd expect. OncePerDay(5) will only show this flash message once every 5 days.
The time based 'oncePer' methods use the cache to store a hash of the message data. A Laravel implementation is included using the default cache driver setup in your config.
Contributing
Please see CONDUCT for details.
Credits
- Lee Overy
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of flasher with dependencies
illuminate/contracts Version ^5.3|^5.4
illuminate/session Version ^5.3|^5.4
php Version >=7.0