---
permalink: /library/toastr/
title: Toastr
description: Easily add customizable, stylish notification messages to your web projects with Toastr, a popular JavaScript library. With a focus on simplicity and flexibility, Toastr is easy to install and use, making it a great choice for any project that wants to engage and inform users.
handler: toastr
data-controller: toastr
---
## Laravel
```shell
composer require php-flasher/flasher-toastr-laravel
```
After installation, you need to run another command to set up the necessary assets for PHPFlasher:
```shell
php artisan flasher:install
```
```shell
composer require php-flasher/flasher-toastr-symfony
```
After installation, you need to run another command to set up the necessary assets for PHPFlasher:
```shell
php bin/console flasher:install
```
```yaml
# config/packages/flasher.yaml
flasher:
plugins:
noty:
scripts:
- '/vendor/flasher/jquery.min.js'
- '/vendor/flasher/toastr.min.js'
- '/vendor/flasher/flasher-toastr.min.js'
styles:
- '/vendor/flasher/toastr.min.css'
options:
# Optional: Add global options here
closeButton: true
```
---
## Usage
---
> The methods described in the **[Usage](/installation/#-usage)** section can also be used with the `notyf` adapter.
---
To display a notification message, you can either use the `toastr()` helper method or obtain an instance of `toastr` from the service container.
Then, before returning a view or redirecting, call the `success()` method and pass in the desired message to be displayed.
{% assign id = '#/ usage error' %}
{% assign type = 'error' %}
{% assign message = site.data.messages[type] | sample %}
{% assign options = '{}' %}
{% include example.html %}
```php
{{ id }}
toastr()->{{ type }}('{{ message }}');
```
---
For more information on Toastr options and usage, please refer to the original documentation at [https://github.com/CodeSeven/toastr](https://github.com/CodeSeven/toastr)
---
> The methods described in the **[Usage](/installation/#-usage)** section can also be used with the `notyf` adapter.
---
When set to `true`, the toast will close when the user hovers over it.
Default ⇒ `false`
```php
toastr()->closeOnHover(bool $closeOnHover = true);
```
{% assign id = '#/ toastr closeOnHover' %}
{% assign type = site.data.messages.types | sample %}
{% assign message = site.data.messages[type] | sample %}
{% assign options = '{"closeOnHover": true, "closeDuration": 10}' %}
{% include example.html %}
```php
{{ id }}
toastr()
->closeOnHover(true)
->closeDuration(10)
->{{ type }}('{{ message }}');
```
---
The class applied to the toast container that determines the position of the toast on the screen (e.g. `toast-top-right`, `toast-bottom-left`).
Default ⇒ `toast-top-right`
```php
toastr()->positionClass(string $positionClass);
```
{% assign id = '#/ toastr positionClass' %}
{% assign type = site.data.messages.types | sample %}
{% assign message = site.data.messages[type] | sample %}
{% assign options = '{"positionClass": "toast-top-center"}' %}
{% include example.html %}
```php
{{ id }}
toastr()
->positionClass('toast-top-center')
->{{ type }}('{{ message }}');
```
---
When set to `true`, the toast can be dismissed by tapping on it.
```php
toastr()->tapToDismiss(bool $tapToDismiss = true);
```
{% assign id = '#/ toastr tapToDismiss' %}
{% assign type = site.data.messages.types | sample %}
{% assign message = site.data.messages[type] | sample %}
{% assign options = '{"tapToDismiss": true}' %}
{% include example.html %}
```php
{{ id }}
toastr()
->tapToDismiss(true)
->{{ type }}('{{ message }}');
```
---
The time in milliseconds to keep the toast visible before it is automatically closed.
Set `timeOut` and `extendedTimeOut` to `0` to make it sticky
Default ⇒ `5000` milliseconds
```php
toastr()->timeOut(int $timeOut, bool $extendedTimeOut = null);
```
{% assign id = '#/ toastr timeOut' %}
{% assign type = site.data.messages.types | sample %}
{% assign message = site.data.messages[type] | sample %}
{% assign options = '{"timeOut": 1000}' %}
{% include example.html %}
```php
{{ id }}
toastr()
->timeOut(1000) // 1 second
->{{ type }}('{{ message }}');
```