hajtuj / laravel-flash-messages
Simple, session based flash messages for Laravel application.
Requires
- php: >=7.3
- illuminate/support: ^7.0|^8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.16
- orchestra/testbench: ^5.0|^6.0
- phpunit/phpunit: ^8.0|^9.0
This package is auto-updated.
Last update: 2025-04-27 16:22:37 UTC
README
Simple, session based flash messages for Laravel applications.
Content
Installation
Just pull package through composer
composer require hajtuj/laravel-flash-messages
Add component tag to Your layout template
<x-flash-message-bootstrap/>
Package is created to work as default with css framework Twitter Bootstrap v4. Information how to add boostrap to Your project or simply add inline link to css file of bootstrap:
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" crossorigin="anonymous">
and js file to make messages able to hide:
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" crossorigin="anonymous"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" crossorigin="anonymous"></script>
Usage
U can simply call flash messages from macro added to RedirectResponse
. Macro name is created from config macro values and type of flash message:
macro prefix + type + macro suffix
public function store() { return redirect('/')->successMsg('Your message'); }
public function store() { return back()->successMsg('Your message'); }
You are able to use handy helper method:
public function store() { flash('message', 'info'); return back(); }
or by chaining it with message type:
public function store() { flash('message')->success(); return back(); }
You can also receive class of FlashMessageContract $flash
in constructor method of your controller:
public function store(FlashMessageContract $flash) { $flash->flashMessage('Hey! Successfully stored resource', 'success'); }
Setup
You can always export config file and views to make your own modifications
exporting config to
config/flash-message.php
$ php artisan flash-message:config
exporting view file to
resources/views/vendor/flash-message/bootstrap.blade.php
$ php artisan flash-message:views
you can add own types of messages in to config file:
/** * Types are used to name classes in html code of alerts */ 'types' => ['primary', 'secondary', 'success', 'danger', 'warning', 'info', 'light', 'dark'],
to modify class for each type add own suffix and prefixes in config file
/** * Class prefix and suffix is added to type of alert to create class name */ 'class' => [ 'prefix' => 'alert-', 'suffix' => '', ],
Donations
If You like my work and U would like to share with me just
License
- MIT license
- Copyright 2020 © bolek.sebastian@gmail.com.