1. Go to this page and download the library: Download php-flasher/flasher-laravel library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
php-flasher / flasher-laravel example snippets
declare(strict_types=1);
use Flasher\Prime\Configuration;
return Configuration::from([
// Default notification library (e.g., 'flasher', 'toastr', 'noty', 'notyf', 'sweetalert')
'default' => 'flasher',
// Path to the main PHPFlasher JavaScript file
'main_script' => '/vendor/flasher/flasher.min.js',
// List of CSS files to style your notifications
'styles' => [
'/vendor/flasher/flasher.min.css',
],
// Set global options for all notifications (optional)
// 'options' => [
// 'timeout' => 5000, // Time in milliseconds before the notification disappears
// 'position' => 'top-right', // Where the notification appears on the screen
// ],
// Automatically inject JavaScript and CSS assets into your HTML pages
'inject_assets' => true,
// Enable message translation using Laravel's translation service
'translate' => true,
// URL patterns to exclude from asset injection and flash_bag conversion
'excluded_paths' => [],
// Map Laravel flash message keys to notification types
'flash_bag' => [
'success' => ['success'],
'error' => ['error', 'danger'],
'warning' => ['warning', 'alarm'],
'info' => ['info', 'notice', 'alert'],
],
// Set criteria to filter which notifications are displayed (optional)
// 'filter' => [
// 'limit' => 5, // Maximum number of notifications to show at once
// ],
// Define notification presets to simplify notification creation (optional)
// 'presets' => [
// 'entity_saved' => [
// 'type' => 'success',
// 'title' => 'Entity saved',
// 'message' => 'Entity saved successfully',
// ],
// ],
]);
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class BookController extends Controller
{
public function saveBook()
{
// Your logic here
flash('Your changes have been saved!');
return redirect()->back();
}
}
namespace App\Http\Controllers;
use Flasher\Prime\FlasherInterface;
class AnotherController extends Controller
{
/**
* If you prefer to use dependency injection
*/
public function register(FlasherInterface $flasher)
{
// Your logic here
$flasher->success('Your changes have been saved!');
// ... redirect or render the view
}
public function update()
{
// Your logic here
app('flasher')->error('An error occurred while updating.');
return redirect()->back();
}
}
flash()->info('This is an informational message.');
flash()->warning('This is a warning message.');
flash()->success('Custom message with options.', ['timeout' => 3000, 'position' => 'bottom-left']);
declare(strict_types=1);
use Flasher\Prime\Configuration;
return Configuration::from([
// ... other configurations
'presets' => [
'entity_saved' => [
'type' => 'success',
'title' => 'Entity Saved',
'message' => 'The entity has been saved successfully.',
],
'entity_deleted' => [
'type' => 'warning',
'title' => 'Entity Deleted',
'message' => 'The entity has been deleted.',
],
],
]);
namespace App\Http\Controllers;
use Illuminate\Http\RedirectResponse;
use App\Http\Controllers\Controller;
class BookController extends Controller
{
/**
* Save a new book entity.
*
* @return RedirectResponse
*/
public function saveBook(): RedirectResponse
{
// Your saving logic here (e.g., validating and storing the book)
// Trigger the 'entity_saved' preset
flash()->preset('entity_saved');
return redirect()->route('books.index');
}
/**
* Delete an existing book entity.
*
* @return RedirectResponse
*/
public function deleteBook(): RedirectResponse
{
// Your deletion logic here (e.g., finding and deleting the book)
// Trigger the 'entity_deleted' preset
flash()->preset('entity_deleted');
return redirect()->route('books.index');
}
}
bash
composer
shell
php artisan flasher:install
bash
php artisan flasher:install --config
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.