GithubHelp home page GithubHelp logo

minkbear / flash Goto Github PK

View Code? Open in Web Editor NEW

This project forked from laracasts/flash

0.0 2.0 0.0 39 KB

Easy flash notifications

Home Page: https://packagist.org/packages/laracasts/flash

PHP 84.77% HTML 15.23%

flash's Introduction

Easy Flash Messages for Your Laravel App

Installation

First, pull in the package through Composer.

Run composer require laracasts/flash

And then, if using Laravel 5, include the service provider within config/app.php.

'providers' => [
    Laracasts\Flash\FlashServiceProvider::class,
];

Usage

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

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()->overlay('Modal Message', 'Modal Title')
  • flash('Message')->important()

Behind the scenes, this will set a few keys in the session:

  • 'flash_notification.message' - The message you're flashing
  • 'flash_notification.level' - A string that represents the type of notification (good for applying HTML class names)

With this message flashed to the session, you may now display it in your view(s). Maybe something like:

@if (session()->has('flash_notification.message'))
    <div class="alert alert-{{ session('flash_notification.level') }}">
        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>

        {!! session('flash_notification.message') !!}
    </div>
@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:

@include('flash::message')

Example

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
</head>
<body>

<div class="container">
    @include('flash::message')

    <p>Welcome to my website...</p>
</div>

<!-- This is only necessary if you do Flash::overlay('...') -->
<script src="//code.jquery.com/jquery.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>

<script>
    $('#flash-overlay-modal').modal();
</script>

</body>
</html>

If you need to modify the flash message partials, you can run:

php artisan vendor:publish

The two package views will now be located in the app/views/packages/laracasts/flash/ directory.

flash('Welcome Aboard!');

return home();

https://dl.dropboxusercontent.com/u/774859/GitHub-Repos/flash/message.png

flash('Sorry! Please try again.', 'danger');

return home();

https://dl.dropboxusercontent.com/u/774859/GitHub-Repos/flash/error.png

flash()->overlay('Notice', 'You are now a Laracasts member!');

return home();

https://dl.dropboxusercontent.com/u/774859/GitHub-Repos/flash/overlay.png

Learn exactly how to build this very package on Laracasts!

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 </body> tag.

<script>
$('div.alert').not('.alert-important').delay(3000).fadeOut(350);
</script>

This will find any alerts - excluding the important ones, which should remain until manually closed by the user - wait three seconds, and then fade them out.

flash's People

Contributors

andrewturner avatar chaot1xmd avatar codeclown avatar freekmurze avatar h4cc avatar hpakdaman avatar imknight avatar jeffreyway avatar kezadias avatar lordmilutin avatar quickliketurtle avatar schnoop avatar sergiogregorutti avatar shaneparsons avatar thoresuenert avatar vinkla avatar waiyan112 avatar zablose avatar

Watchers

 avatar  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.