Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mtxr/laravel-flash-message
Flash messages made easy. Based on laracasts/flash
https://github.com/mtxr/laravel-flash-message
Last synced: 3 months ago
JSON representation
Flash messages made easy. Based on laracasts/flash
- Host: GitHub
- URL: https://github.com/mtxr/laravel-flash-message
- Owner: mtxr
- Created: 2016-08-10T02:13:32.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-09-14T00:53:01.000Z (over 8 years ago)
- Last Synced: 2024-07-22T21:56:52.891Z (5 months ago)
- Language: PHP
- Homepage:
- Size: 49.8 KB
- Stars: 3
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Flash messages made easy. Based on laracasts/flash
## Installation
First, pull in the package through Composer.
Run `composer require mtxr/laravel-flash-message`
And then, if using Laravel 5, include the service provider within `config/app.php`.
```php
'providers' => [
FlashMessage\FlashServiceProvider::class,
];
```## Usage
Within your controllers, before you perform a redirect...
```php
public function store()
{
flash('Welcome Aboard!');return home();
}
```You may also do:
- `flash('Message', 'info')`
- `flash('Message', 'success')`
- `flash('Message', 'danger')`
- `flash('Message', 'warning')`
- `flash('Message')->important()`Adding Icons:
- `flash('Message')->icon('fa fa-exclamation-circle')`Deleting last message:
- `flash()->delete()`Clearing message queue:
- `flash()->clear()`If you need, you can flash two messages in the same request:
```php
public function welcome()
{
flash('Welcome Aboard!', 'success');flash('Request Failed!', 'error');
return home();
}
```Behind the scenes, this will set a few keys in the session:
- 'flash_notification.messages' - The array of messages you have
With this message flashed to the session, you may now display it in your view(s). Maybe something like:
```html
@if (session()->has('flash_notification.messages'))
@foreach(session('flash_notification.messages') as $messageData)
@endforeach
@endif
```> Note that this package is optimized for use with Twitter Bootstrap.
Because flash messages and overlays are so common, if you want, you may use (or modify) the views that are included with this package. Simply append to your layout view:
```html
@include('flash::message')
```## Example
```html
Document
@include('flash::message')
Welcome to my website...
```
If you need to modify the flash message partials, you can run:
```bash
php artisan vendor:publish
```The package view will now be located in the `app/views/packages/mtxr/laravel-flash-message/` directory.
## Hiding Flash Messages
A common desire is to display a flash message for a few seconds, and then hide it. To handle this, write a simple bit of JavaScript. For example, using jQuery, you might add the following snippet just before the closing `