2017 © Pedro Peláez
 

library notification

image

jralph/notification

  • Monday, December 1, 2014
  • by jralph
  • Repository
  • 1 Watchers
  • 0 Stars
  • 17 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

Laravel 4 Flash Notifications

Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

A simple and easy to use flash notification setup for Laravel 4., (*2)

Extension

By default, the notifications are handled by the Illuminate Session Store but this can be easily replaced by implementing the Jralph\Notification\Contracts\Store contract provided and then bound using the IoC container. Once done, any existing code will continue to work as normal. For example, you could easily switch out the Session Store for your own form of storage for flash messages., (*3)

Usage

Laravel

To use the Notification in Laravel, you can add the service provider and alias to your app/config/app.php file., (*4)

<?php
...
    'providers' => array(
        ...
        'Jralph\Notification\NotificationServiceProvider',
        ...
    ),
    ...
    'aliases' => array(
        ...
        'Notification' => 'Jralph\Notification\Facades\Notification'
        ...
    ),
...
?>

Once this is done, you can use the facade like so., (*5)

<?php
    Notification::put('key', 'value');
?>

See below for more information on the methods the class provides., (*6)

Methods

PUT, (*7)

The put method flashes a key => value message to the session., (*8)

<?php
    Notification::put('key', 'value');
?>

GET, (*9)

The get method retrieves a value from the session by key., (*10)

<?php
    Notification::get('key'); // If using the above put somewhere, this will return (string) 'value'.
?>

HAS, (*11)

The has method checks if a key exists in the notification session storage., (*12)

<?php
    Notification::has('key',); // If using the above put somewhere, this will return true.
?>

TAGS, (*13)

The tags method can be combined with the put method to tag specific notifications., (*14)

<?php
    Notification::tags(['tag1', 'tag2'])->put('key', 'value');
?>

TAG, (*15)

The tag method is used to retrieve an array of notifications attached to a specific tag., (*16)

<?php
    Notification::tag('tag1'); // Returns an array of all notifications tagged as `tag1`.
?>

Example Usage

In a controller processing login somewhere., (*17)

fails())
        {
            Notification::tags(['error'])->put('validation_failed', 'The form validation has failed.'); // Note you could pass an array as the value.
            return Redirect::back();
        }

        // Process User Login
    }

}
?>

Somewhere in a view displaying the login form somewhere., (*18)

@foreach (Notification::tag('error') as $key => $notification)
    <div class="notification">
        <strong>{{ $key }}</strong> {{ $notification }}
    </div>
@endforeach

You could also disregard the tags for a simpler approach and just display the validation failed error., (*19)

@if (Notification::has('validation_failed'))
    <div class="notification">
        <strong>Validation Failed</strong> {{ Notification::get('validation_failed') }}
    </div>
@endif

Upcoming Features

  • Add a default tag that is not overwritten.
    • OR add the Notification::all() method to retrieve all messages.

The Versions

01/12 2014

dev-master

9999999-dev

  Sources   Download

MIT

The Requires

 

The Development Requires

by Joseph Ralph

09/10 2014

1.1.1

1.1.1.0

  Sources   Download

MIT

The Requires

 

The Development Requires

by Joseph Ralph

09/10 2014

1.1.0

1.1.0.0

  Sources   Download

MIT

The Requires

 

The Development Requires

by Joseph Ralph

09/10 2014

1.0.2

1.0.2.0

  Sources   Download

MIT

The Requires

 

The Development Requires

by Joseph Ralph

09/10 2014

1.0.1

1.0.1.0

  Sources   Download

MIT

The Requires

 

The Development Requires

by Joseph Ralph

09/10 2014

1.0.0

1.0.0.0

  Sources   Download

The Requires

 

The Development Requires

by Joseph Ralph