willishq/laravel5-flash

This package is abandoned and no longer maintained. No replacement package was suggested.

Flash message management for Laravel 5.

v0.2 2015-01-28 14:50 UTC

This package is auto-updated.

Last update: 2021-09-12 20:23:36 UTC


README

Inspired by Laracasts Flash

Installation

Install via composer:

composer require willishq/laravel5-flash

Usage

Ideally use within your base controller as so:

namespace App\Http\Controllers;

use Illuminate\Foundation\Bus\DispatchesCommands;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Willishq\Flash\Flash;

abstract class Controller extends BaseController {

	use DispatchesCommands, ValidatesRequests;
	/**
	 * @var Flash
	 */
	protected $flash;
	public function __construct(Flash $flash)
	{
		$this->flash = $flash;
	}
}

To fire off a flash message:

class FooController extends BaseController {

	public function somethingNeat()
	{
	    // epic codes
	    $this->flash->success('success message');
	    return redirect('/');
	}
}

To display flash messages in your view:

@if($flash->exists())
	@if($flash->isPanel())
		<div class="panel">
			<h5>{{ $flash->title }}</h5>
			<p>{{ $flash->message }}</p>
		</div>
	@else
		<div data-alert class="alert-box {{ $flash->type }}">
			<p>{{ $flash->message }}</p>
			<a href="#" class="close">&times;</a>
		</div>
	@endif

@endif