GithubHelp home page GithubHelp logo

notifications's Introduction

Notifications

Installation

First, pull in the package through Composer.

"require": {
    "arthurguy/notifications": "~1.0"
}

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

'providers' => [
    'ArthurGuy\Notifications\NotificationServiceProvider'
];

And, for convenience, add a facade alias to this same file at the bottom:

'aliases' => [
    'Flash' => 'ArthurGuy\Notifications\NotificationFacade'
];

Usage

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

public function store()
{
    Notification::message('Welcome Aboard!');

    return Redirect::home();
}

You may also do:

  • Notification::info('Message')
  • Notification::success('Message')
  • Notification::error('Message')
  • Notification::warning('Message')

Again, if using Laravel, this will set a few keys in the session:

  • 'flash_notification.message' - The message you're flashing
  • 'flash_notification.details' - A MessageBag object, ideal for field error messages
  • 'flash_notification.level' - A string that represents the type of notification (good for applying HTML class names)

Alternatively, again, if you're using Laravel, you may reference the flash() helper function, instead of the facade. Here's an example:

/**
 * Destroy the user's session (logout).
 *
 * @return Response
 */
public function destroy()
{
    Auth::logout();

    notification()->success('You have been logged out.');

    return home();
}

Or, for a general information flash, just do: notification('Some message');.

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::get('flash_notification.level') }}">
        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>

        {{ Session::get('flash_notification.message') }}
    </div>
@endif

notifications's People

Contributors

jeffreyway avatar arthurguy avatar quickliketurtle avatar kezadias avatar vinkla avatar thoresuenert avatar

Watchers

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