19
NovFlash messages are a great way to add some simple notifications to users of your website or application about important events that may have happened. PHPFlasher gives a straightforward way to give feedback messages on the current or next page to users with the flashing system. The flashing system basically makes it possible to record a message and store it within the session so that it can be retrieved when needed.
PHP Flasher helps you to add flash notifications to your PHP projects. This library was developed with the idea that you should be able to add flash notifications to your application with ease and with few lines of code. No application-wide rewrites and no big investments upfront.
PHPFlasher supports many notification libraries: tailwindcss, bootstrap, toastr.js, sweet alert 2, pnotify, noty, notyf, and even show desktop notifications.
This library is designed, so you can take full control when creating your notifications :
PHPFlasher can be installed using composer.
composer require php-flasher/flasher
PHPFlasher also offers solid integration with Laravel and Symfony :
composer require php-flasher/flasher-laravel
composer require php-flasher/flasher-symfony
Additionally, you may want to install an extra adapter (library) to display a specific type of notifications, you can find the adapters in the menu.
If you’re using a framework like Laravel or Symfony, just grab an instance of FlasherInterface from the container
<?php
namespace App\Controller;
use Flasher\Prime\FlasherInterface;
class NotifyController
{
public function flasher(FlasherInterface $flasher)
{
// ...
$flasher->addSuccess('Data has been saved successfully!');
flasher('Data has been saved successfully!') // only for the Laravel framework
// ... redirect or render a view here
}
}
There are also 4 shortcuts for the addFlash() method :
$flasher->addSuccess('success message');
$flasher->addError('error message');
$flasher->addWarning('warning essage');
$flasher->addInfo('info message');
There are only two main steps to render a notification : build
and flash
// Step 1: create your notification and add options
$builder = $flasher->type('success')
->message('your custom message')
->priority(2)
->handler('toastr')
->option('timer', 5000)
;
// Step2 : Store the notification in the session
$builder->flash();
$builder = $flasher->type('error', 'An error has occurred please try again later.');
$builder->flash();
By following the above-given instructions you can learn the basic use of Php Flasher. But if you want to dig more you can visit its detailed documentation and View source code on Github.
Published at : 19-11-2021
I am a highly results-driven professional with 12+ years of collective experience in the grounds of web application development especially in laravel, native android application development in java, and desktop application development in the dot net framework. Now managing a team of expert developers at Codebrisk.
Launch project