2017 © Pedro Peláez
 

library flash-message

image

thecodemill/flash-message

  • Friday, January 19, 2018
  • by TheCodeMill
  • Repository
  • 1 Watchers
  • 0 Stars
  • 19 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 36 % Grown

The README.md

FlashMessage

A simple PHP container for passing session (flash) messages between page redirects., (*1)

Installation

Install the FlashMessage package via Composer:, (*2)

composer require thecodemill/flash-message

Usage

FlashMessage is used to make messages of 4 different statuses:, (*3)

  • INFO
  • SUCCESS
  • WARNING
  • DANGER

A message can be created by instantiating a new TheCodeMill\FlashMessage\Message class, with the appropriate arguments:, (*4)

use TheCodeMill\FlashMessage\Message;

$message = new Message('The problem with the gene pool is there’s no lifeguard', Message::STATUS_INFO);

Alternatively, static helper methods are available to automatically generate a message of each particular status:, (*5)

use TheCodeMill\FlashMessage\Message;

// Info
$info = Message::info('I have noticed something strange.');

// Warning
$warning = Message::warning('This could be a problem.');

// Danger
$danger = Message::danger('Yes, it was definitely a problem.');

// Success
$success = Message::success('All fixed!');

These messages can then be passed into session storage and flashed between page redirects., (*6)

Here's a Laravel example:, (*7)

Route::post('/submit', function () {
    // Do something
    // ...

    // Now redirect
    return redirect('/success')
        ->with('message', Message::success('Thanks for submitting.'));
});

To output the message, we may use the content() and status() methods on the Message object., (*8)

Note: You may notice that the status types tie in nicely with Bootstrap's default types., (*9)

Here's another Laravel Blade example:, (*10)

@if($message = session('message'))
    <div class="alert alert-{{ strtolower($message->status()) }} alert-dismissible" role="alert">
        <button type="button" class="close" data-dismiss="alert">
            <span>&times;</span>
            <span class="sr-only">Close</span>
        </button>

        {{ $message->content() }}
    </div>
@endif

Author

The Versions

19/01 2018

dev-master

9999999-dev

  Sources   Download

MIT

The Development Requires

19/01 2018

1.0

1.0.0.0

  Sources   Download

MIT

The Development Requires