Wallogit.com
2017 © Pedro Peláez
Laravel JS alerts/ toasts
A laravel alerts utility that help you show Toasts directly in your blade template instead of Javascript files., (*1)
Follow below steps, (*2)
composer require faisalahsan/laraalerts in your terminalAdd Service Provider
Open config/app.php and add FaisalAhsan\LaraAlerts\LaraAlertServiceProvider::class to the end of providers array:, (*3)
'providers' => array(
....
FaisalAhsan\LaraAlerts\LaraAlertServiceProvider::class,
),
Register Facade, (*4)
'aliases' => array(
....
'Toast' => FaisalAhsan\LaraAlerts\Facade\ToastFacade::class,
),
Run below command, (*5)
php artisan vendor:publish
Include files in your layout, (*6)
<link rel="stylesheet" href="/css/toast.css">
<script type="text/javascript" src="/js/toast.js"></script>
In you blade template, (*7)
{{ Toast::info( 'Saved', 'Item saved')->run() }}
info('heading', 'message text'), (*8)
First parameter shows title of the Toast
Second parameter shows message to be display
{{ Toast::info('Info', 'Info Toast')->run() }}
warning('heading', 'message text'), (*9)
First parameter shows title of the Toast
Second parameter shows message to be display
{{ Toast::info('Warning', 'Warning Toast')->run() }}
error('heading', 'message text'), (*10)
First parameter shows title of the Toast
Second parameter shows message to be display
{{ Toast::info('Error', 'Error Toast')->run() }}
success('heading', 'message text'), (*11)
First parameter shows title of the Toast
Second parameter shows message to be display
{{ Toast::info('Success', 'Success Toast')->run() }}
fade() for fade transitions, (*12)
{{ Toast::info('Success', 'Success Toast')->fade()->run() }}
slide() for slide up and down transitions, (*13)
{{ Toast::info('Success', 'Success Toast')->slide()->run() }}
plain() simple show from and hide to corner transition, (*14)
{{ Toast::info('Success', 'Success Toast')->plain()->run() }}
showCloseButton(true) Pass boolean (
trueorfalse) to show or hide cross button on toast, by default it is true, (*15)
{{ Toast::info('Success', 'Success Toast')->showCloseButton()->run() }}
hideAfter(3000) Specify the duration, for how long toast will be visile or pass
falseto make it sticky, (*16)
Hide after 3 seconds {{ Toast::info('Duration', 'This toast will be disappear after 3 seconds')->hideAfter(3000)->run() }}, (*17)
Sticky {{ Toast::info('Duration', 'This toast is a sticky toast.')->hideAfter(false)->run() }}, (*18)
noOfToastToShow(1) how many toasts can be displayed in stack, (*19)
{{ Toast::info('Success', 'Success Toast')->noOfToastToShow(3)->run() }}
position() where toast will be displyed, (*20)
position can be one of these
['bottom-left', 'bottom-right', 'top-right', 'top-left', 'bottom-center', 'top-center', 'mid-center']
{{ Toast::info('Toast Position', 'Toast is displayed in the center position.')->position('top-center')->run() }}
or simple object
{ top: - , bottom: -, left: -, right: - }
{{ Toast::info('Toast Position', 'Toast is positioned using object.')->position("{ top: '12' , bottom: '12', left: '12', right: '12' }")->run() }}
textAlign() define text alignment e.g. left, right, center, (*21)
{{ Toast::info('Text Alignment', 'Text has left alignment.')->textAlign('left')->run() }}
loader('#9EC600' ) show loader with color value, (*22)
{{ Toast::info('Text Alignment', 'Text has left alignment.')->loader('#9EC600')->run() }}
color value can be Hexa value or Html color name
Special thanks to Kamran Ahmed, (*23)