Skip to content

laravel24/laravel-alert

 
 

Repository files navigation

Laravel Alert

alert

A Bootstrap alert helper for Laravel.

// Flash alert messages.
alert()->success('I hope I didn\'t brain my damage.');

// Use the facade.
Alert::info('Smithers, release the hounds.');

// Dependency injection example.
$alert->warning('¡Ay, caramba!');

Build Status StyleCI Coverage Status Latest Version License

Installation

Require this package, with Composer, in the root directory of your project.

$ composer require vinkla/alert

Add the service provider to config/app.php in the providers array, or if you're using Laravel 5.5, this can be done via the automatic package discovery.

Vinkla\Alert\AlertServiceProvider::class

If you want you can use the facade. Add the reference in config/app.php to your aliases array.

'Alert' => Vinkla\Alert\Facades\Alert::class

Include the alert view within your view templates with blade.

@include('alert::bootstrap')

Usage

Alert

This is the class of most interest. It is bound to the ioc container as alert and can be accessed using the Facades\Alert facade.

Facades\Alert

This facade will dynamically pass static method calls to the alert object in the ioc container which by default is the Alert class.

AlertServiceProvider

This class contains no public methods of interest. This class should be added to the providers array in config/app.php. This class will setup ioc bindings.

Examples

Here you can see an example of just how simple this package is to use. Out of the box it will just work:

// You can alias this in config/app.php.
use Vinkla\Alert\Facades\Alert;

Alert::danger('Eat my shorts.');
// We're done here - how easy was that, it just works!

Alert::error('You, sir, are an idiot.');
// This example is simple and there are far more methods available.

If you prefer to use dependency injection over facades like me, then you can inject the manager:

use Vinkla\Alert\Alert;

class Foo
{
    protected $alert;

    public function __construct(Alert $alert)
    {
        $this->alert = $alert;
    }

    public function bar($message)
    {
        $this->alert->warning($message)
    }
}

App::make('Foo')->bar('I see the light... it burns!');

There is also a helper function if that is what you prefer.

// Use the methods.
alert()->error('I feel like such a tool.');

// The alert function accepts message and style.
alert('Marge, can I go out and play?', 'info');

License

MIT © Vincent Klaiber

Packages

No packages published

Languages

  • PHP 96.5%
  • HTML 3.5%