Coder Social home page Coder Social logo

laravel-flash's Introduction

Laravel Flash

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

Install

Via Composer

$ composer require neimarperez/laravel-flash

And then include the service provider within app/config/app.php.

'providers' => [
    NeimarPerez\Flash\ServiceProvider::class
];

If you need to modify the configuration or the views, you can run:

php artisan vendor:publish --provider="NeimarPerez\Flash\ServiceProvider"

The package views will now be located in the app/resources/views/vendor/flash/ directory and the configuration will be located at app/config/flash.php.

Usage

Within your controllers, before you perform a redirect...

public function store(Flash $flash)
{
    flash()->message('Welcome Aboard!');

    return redirect()->route('dashboard');
}

You may also do:

  • flash()->message('Message')
  • flash()->success('Message')
  • flash()->info('Message')
  • flash()->warning('Message')
  • flash()->error('Message')
  • flash()->overlay('Modal Message', 'Modal Title')

Again, this will set one key in the session:

  • flash_notification.messages - The messages you're flashing, each message is contained as an array
    • message - The message you're flashing
    • level - A string that represents the type of notification
    • title - A string that will show up as the modal title
    • overlay - A boolean that indicates whether or not the flash is an overlay

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:

@include('flash::messages')

Example

<!doctype html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Laravel PHP Framework</title>
        <!-- Twitter Bootstrap -->
        <link rel="stylesheet" href="//cdn.jsdelivr.net/bootstrap/3.3.1/css/bootstrap.min.css">
        <link rel="stylesheet" href="//cdn.jsdelivr.net/bootstrap/3.3.1/css/bootstrap-theme.min.css">
        <!-- ZURB Foundation -->
        <link rel="stylesheet" href="//cdn.jsdelivr.net/foundation/5.4.7/stylesheets/foundation.min.css">
    </head>

    <body>
        <div class="container">
            @include('flash::messages')
        </div><!-- /.container -->

        <!-- jQuery -->
        <script src="//cdn.jsdelivr.net/jquery/2.1.1/jquery.min.js"></script>
        <!-- Twitter Bootstrap -->
        <script src="//cdn.jsdelivr.net/bootstrap/3.3.1/js/bootstrap.min.js"></script>
        <!-- ZURB Foundation -->
        <script src="//cdn.jsdelivr.net/foundation/5.4.7/javascripts/foundation.min.js"></script>
        <script>
            // Twitter Bootstrap
            $('#flash-overlay-modal').modal();

            // ZURB Foundation
            $('#flash-overlay-modal').foundation('reveal', 'open');
        </script>
    </body>
</html>

Message (Defaults to Info)

flash()->message('Welcome aboard!');

return redirect()->route('dashboard');

Success

flash()->success('You successfully read this important alert message.');

return redirect()->route('dashboard');

Info

flash()->info('This alert needs your attention, but it\'s not super important.');

return redirect()->route('dashboard');

Warning

flash()->warning('Better check yourself, you\'re not looking too good.');

return redirect()->route('dashboard');

Error

flash()->error('Change a few things up and try submitting again.');

return redirect()->route('dashboard');

Important

flash('You successfully read this important alert message.')->important();

return redirect()->route('dashboard');

Modal / Overlay

flash()->overlay('One fine body...');

return redirect()->route('dashboard');

Laravel Validation

$validator = Validator::make(
    ['name' => 'Invalid'],
    ['name' => 'required|min:8']
);

flash()->error($validator->messages());

return redirect()->route('dashboard');

Chain Messages

flash()->success('You successfully read this important alert message.')
       ->info('This alert needs your attention, but it\'s not super important.')
       ->warning('Better check yourself, you\'re not looking too good.')
       ->error('Change a few things up and try submitting again.')
       ->overlay('One fine body...');

return redirect()->route('dashboard');

Change log

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING and CONDUCT for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

laravel-flash's People

Watchers

Neimar Perez avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.