luishuh / toastr-laravel-v2
Toastr notifications in laravel, new feature added. This library was created by roksta21@gmail.com.
Requires
- php: >=5.4.0
- illuminate/session: ~5.0
Requires (Dev)
- mockery/mockery: dev-master
This package is not auto-updated.
Last update: 2025-07-06 09:26:01 UTC
README
Simple toastr notifications for laravel
Installation
Install Toastr via npm
npm install toastr --save
Require the js in resources/assets/js/bootstrap.js as
window.toastr = require('toastr');
Import the sass in resources/assets/sass/app.scss as
@import "node_modules/toastr/toastr";
then build via npm npm run prod
.
Install via composer
composer require "luishuh/toastr-laravel-v2:@dev"
Include the service provider and its alias within the config/app.php
.
'providers' => [ LuisHuh\Toastr\ToastrServiceProvider::class, ]; 'aliases' => [ 'Toast' => LuisHuh\Toastr\Toast::class, ];
Run
php artisan vendor:publish --provider="LuisHuh\Toastr\ToastrServiceProvider"
to publish the package view in your resources/assets/vendor/luishuh/toastr.blade.php
Add @include('vendor.luishuh.toastr')
in your main view, eg,
<!DOCTYPE html> <html> <head> <title></title> <link rel="stylesheet" type="text/css" href="/css/app.css"> </head> <body> <div id="app"></div> <script type="text/javascript" src="js/app.js"></script> @include('vendor.luishuh.toastr') </body> </html>
Use
Just use the helper function toast()
to make the notifier.
toast()->success('message', 'title'); toast()->info('message', 'title'); toast()->warning('message', 'title'); toast()->error('message', 'title');
You may specify the timeout duration by
toast()->success('message', 'title')->timeOut(5000);
You may activate the close button by
toast()->success('message', 'title')->closeButton(true);
You may activate debug by
toast()->success('message', 'title')->debug(true);
You may add the newest on top by
toast()->success('message', 'title')->newestOnTop(true);
You may activate the progressBar by
toast()->success('message', 'title')->progressBar(true);
You may change the position by
toast()->success('message', 'title')->positionClass('top-right'); toast()->success('message', 'title')->positionClass('bottom-right'); toast()->success('message', 'title')->positionClass('bottom-left'); toast()->success('message', 'title')->positionClass('top-left'); toast()->success('message', 'title')->positionClass('top-full-width'); toast()->success('message', 'title')->positionClass('bottom-full-width'); toast()->success('message', 'title')->positionClass('top-center'); toast()->success('message', 'title')->positionClass('bottom-center');
You may prevent duplicates by
toast()->success('message', 'title')->preventDuplicates(true);
You may specify the show duration by
toast()->success('message', 'title')->showDuration(300);
You may specify the hide duration by
toast()->success('message', 'title')->hideDuration(1000);
You may extend the timeout duration by
toast()->success('message', 'title')->extendedTimeOut(1000);
you may specify the speed of the animation to show and hide toastr by
toast()->success('message', 'title')->showEasing('swing'); toast()->success('message', 'title')->hideEasing('linear');
you can specify the type of the animation to show and hide toastr by
toast()->success('message', 'title')->showMethod('fadeIn'); toast()->success('message', 'title')->hideMethod('fadeOut');
you may add behavior on toast click
<script type="text/javascript"> function behavior(){ alert("Hello World"); } </script>
toast()->success('message', 'title')->onclick('behavior');
you may add all the options, you do not need to add all, only the ones you need.
toast()->success('message', 'title')->options([ 'closeButton' => true, 'debug' => false, 'newestOnTop' => false, 'progressBar' => true, 'positionClass' => 'toast-top-right', 'preventDuplicates' => false, 'onclick' => 'behavior', 'showDuration' => 300, 'hideDuration' => 1000, 'timeOut' => 5000, 'extendedTimeOut' => 1000, 'showEasing' => 'swing', 'hideEasing' => 'linear', 'showMethod' => 'fadeIn', 'hideMethod' => 'fadeOut' ]);