palpalani/laravel-toastr

Implements toastr.js for Laravel projects

Fund package maintenance!
palpalani

0.3.0 2024-04-18 05:01 UTC

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

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 toast
  • Toastr::error($message, $title = null, $options = []) - add an error toast
  • Toastr::info($message, $title = null, $options = []) - add an info toast
  • Toastr::success($message, $title = null, $options = []) - add a success toast
  • Toastr::add($type: warning|error|info|success, $message, $title = null, $options = []) - add a toast
  • Toastr::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.