/laravel5-flash

Laravel 5 Flash messages inspired by Laracasts Flash Messages

Primary LanguagePHPMIT LicenseMIT

Laravel 5 Flash Message Helper

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