From 8994a0f36cefbe3c1e90c6d9a128aa41065a368e Mon Sep 17 00:00:00 2001 From: joeknex <6383286+joeknex@users.noreply.github.com> Date: Sun, 24 May 2020 04:05:08 +0100 Subject: [PATCH] Updated Readme.md file. Added error(), primary(), secondary(), light() and dark() themes. Added dismissible() and fixed() options. Added alert.blade.php file. --- readme.md | 152 +++++++++++++------------- src/Laracasts/Flash/FlashNotifier.php | 95 ++++++++++++++-- src/Laracasts/Flash/Message.php | 14 +++ src/views/alert.blade.php | 15 +++ src/views/message.blade.php | 22 ++-- src/views/modal.blade.php | 11 +- 6 files changed, 205 insertions(+), 104 deletions(-) create mode 100644 src/views/alert.blade.php diff --git a/readme.md b/readme.md index a47bea0..871fe1c 100644 --- a/readme.md +++ b/readme.md @@ -2,6 +2,8 @@ This composer package offers a Twitter Bootstrap optimized flash messaging setup for your Laravel applications. +> [Learn exactly how to build this very package on Laracasts!](https://laracasts.com/lessons/flexible-flash-messages) + ## Installation Begin by pulling in the package through Composer. @@ -10,15 +12,17 @@ Begin by pulling in the package through Composer. composer require laracasts/flash ``` -Next, as noted above, the default CSS classes for your flash message are optimized for Twitter Bootstrap. As such, either pull in the Bootstrap's CSS within your HTML or layout file, or write your own CSS based on these classes. +Next, as noted above, the default CSS classes for your flash message are optimized for Twitter Bootstrap. As such, either pull in the Bootstrap's CSS within your HTML or layout file, or write your own CSS based on these classes: ```html - + ``` +(See https://getbootstrap.com/docs/ for the latest CSS version) + ## Usage -Within your controllers, before you perform a redirect, make a call to the `flash()` function. +Within your controllers, before you perform a redirect, make a call to the `flash()` function: ```php public function store() @@ -29,109 +33,109 @@ public function store() } ``` -You may also do: +You may also append to the function with the following actions: + +Flash Alert Themes: - `flash('Message')->success()`: Set the flash theme to "success". -- `flash('Message')->error()`: Set the flash theme to "danger". - `flash('Message')->warning()`: Set the flash theme to "warning". -- `flash('Message')->overlay()`: Render the message as an overlay. -- `flash()->overlay('Modal Message', 'Modal Title')`: Display a modal overlay with a title. -- `flash('Message')->important()`: Add a close button to the flash message. -- `flash('Message')->error()->important()`: Render a "danger" flash message that must be dismissed. +- `flash('Message')->danger()` / `flash('Message')->error()`: Set the flash theme to "danger". +- `flash('Message')->info()`: Set the flash theme to "info". +- `flash('Message')->primary()`: Set the flash theme to "primary". +- `flash('Message')->secondary()`: Set the flash theme to "secondary". +- `flash('Message')->light()`: Set the flash theme to "light". +- `flash('Message')->dark()`: Set the flash theme to "dark". -With this message flashed to the session, you may now display it in your view(s). Because flash messages and overlays are so common, we provide a template out of the box to get you started. You're free to use - and even modify to your needs - this template how you see fit. +Flash Alert Dismissible Options: -```html -@include('flash::message') -``` +- `flash('Message')->dismissible()`: Add a close button to the flash message. +- `flash('Message')->important()`: Add a close button to the flash message and prevent auto hiding (if in combination with Javascript). +- `flash('Message')->fixed()`: Stops the flash message from ever being closed (Overrides `dismissible()` and `important()`). -## Example +Render as Overlay Modal: -```html - - -
- -Welcome to my website...
-Welcome to my website...
+` tag: -return home(); +```html + ``` -![https://dl.dropboxusercontent.com/u/774859/GitHub-Repos/flash/message.png](https://dl.dropboxusercontent.com/u/774859/GitHub-Repos/flash/message.png) +This will find any alerts (excluding the `->important()` ones) which should remain visible until manually closed by the user, wait three seconds, and then fade out. -```php -flash('Sorry! Please try again.')->error(); +### Multiple Flash Messages -return home(); -``` - -![https://dl.dropboxusercontent.com/u/774859/GitHub-Repos/flash/error.png](https://dl.dropboxusercontent.com/u/774859/GitHub-Repos/flash/error.png) +If you need to flash multiple alerts do the following: ```php -flash()->overlay('You are now a Laracasts member!', 'Yay'); +flash('Message 1')->warning(); +flash('Message 2')->error()->important(); +flash('Message 3')->info(); -return home(); +return redirect('somewhere'); ``` -![https://dl.dropboxusercontent.com/u/774859/GitHub-Repos/flash/overlay.png](https://dl.dropboxusercontent.com/u/774859/GitHub-Repos/flash/overlay.png) - -> [Learn exactly how to build this very package on Laracasts!](https://laracasts.com/lessons/flexible-flash-messages) - -## 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 `` tag. +## Example ```html - + + +
+ +
+ + +
+