palpalani / laravel-toastr
Implements toastr.js for Laravel projects
Fund package maintenance!
palpalani
Installs: 20 540
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 3
Forks: 2
Open Issues: 0
Requires
- php: ^8.2
- illuminate/session: ^10.0|^11.0
- illuminate/support: ^10.0|^11.0
Requires (Dev)
- laravel/pint: ^1.15
- orchestra/testbench: ^8.0|^9.0
- phpunit/phpunit: ^10.0|^11.0
- vimeo/psalm: ^5.0
README
Implements toastr.js for Laravel. Toastr.js is a Javascript library for non-blocking notifications.
Installation
NPM
To install a plugin via npm run
npm install toastr
Composer
You can also install the package via composer:
composer require palpalani/laravel-toastr
Configuration
Publish the config file with
php artisan vendor:publish --provider="palPalani\Toastr\ToastrServiceProvider" --tag="laravel-toastr-config"
This is the contents of the published config file:
return [ 'options' => [ "progressBar" => true, "positionClass" =>"toast-bottom-right", "preventDuplicates"=> false, "showDuration" => 300, "hideDuration" => 1000, "timeOut" => 5000, "extendedTimeOut" => 1000, "showEasing" => "swing", "hideEasing"=> "linear", "showMethod" => "fadeIn", "hideMethod" => "fadeOut", ] ];
If you want, edit config/toastr.php
and set the options
array to whatever you want to pass to Toastr (this step is optional). These options are set as
the default options and can be overridden by passing an array of options to any of the methods in the Usage section.
Usage
Include jQuery, toastr.js and plugin styles in your master view template.
Link to toastr.min.css:
<link href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.css" rel="stylesheet"/>
Link to toastr.min.js:
<script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.js"></script>
After everything is done, insert the string below in your template just before body closing tag or after toastr.js script instantiated in your file.
{!! Toastr::render() !!}
Then use these methods in your controllers to insert a toast:
Toastr::warning($message, $title = null, $options = [])
- add a warning toastToastr::error($message, $title = null, $options = [])
- add an error toastToastr::info($message, $title = null, $options = [])
- add an info toastToastr::success($message, $title = null, $options = [])
- add a success toastToastr::add($type: warning|error|info|success, $message, $title = null, $options = [])
- add a toastToastr::clear()
- clear all current toasts don't forget to use it
For a list of available options, see toastr.js' documentation.
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Versioning
We use SemVer for versioning. For the versions available, see the tags on this repository.
Credits
License
The MIT License (MIT). Please see License File for more information.