If you find PHPFlasher useful, we would greatly appreciate your support in the form of a star rating ⭐ on GitHub or by sharing the project on Twitter click here. Your feedback helps us keep the package up-to-date and well-maintained. Thank you


Installation

Laravel:

composer require php-flasher/flasher-toastr-laravel


Symfony:

composer require php-flasher/flasher-toastr-symfony

Usage

#/ toastr

namespace App\Controller;

class AppController
{
    public function save()
    {        
        toastr()->addInfo('Heads up: This may take a while.');
    }
} 

Modifiers

For more information on Toastr options and usage, please refer to the original documentation at https://github.com/CodeSeven/toastr


The methods described in the Usage section can also be used with the toastr adapter.


persistent

Prevent from Auto Hiding.

toastr()->persistent();
#/ toastr persistent

toastr()
    ->persistent()
    ->closeButton()
    ->addWarning('Your password may be at risk.');

closeButton

When set to true, a close button is displayed in the toast notification.

toastr()->closeButton(bool $closeButton = true);
#/ toastr closeButton

toastr()
    ->closeButton(true)
    ->addWarning('Your donation may not have been received.');

closeHtml

The HTML content of the close button.

Default ⇒ <button type="button">&times;</button>

toastr()->closeHtml(string $closeHtml);
#/ toastr closeHtml

toastr()
    ->closeButton(true)
    ->closeHtml('⛑')
    ->addWarning('Exercise caution when performing this action.');

closeOnHover

When set to true, the toast will close when the user hovers over it.

Default ⇒ false

toastr()->closeOnHover(bool $closeOnHover = true);
#/ toastr closeOnHover

toastr()
    ->closeOnHover(true)
    ->closeDuration(10)
    ->addInfo('Your message has been sent and a confirmation email has been sent.');

escapeHtml

When set to true, HTML in the toast message will be escaped.

Default ⇒ false

toastr()->escapeHtml(bool $escapeHtml = true);
#/ toastr escapeHtml false

toastr()
    ->escapeHtml(false)
    ->addError('<strong>We’re sorry</strong>, but an error occurred.');
#/ toastr escapeHtml true

toastr()
    ->escapeHtml(true)
    ->addError('<strong>We’re sorry</strong>, but an error occurred.');

newestOnTop

When set to true, new toast notifications are displayed above older ones.

Default ⇒ true

toastr()->newestOnTop(bool $newestOnTop = true);
#/ toastr newestOnTop

toastr()
    ->newestOnTop(true)
    ->addError('There was an issue updating your address.');

positionClass

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

toastr()->positionClass(string $positionClass);
#/ toastr positionClass

toastr()
    ->positionClass('toast-top-center')
    ->addSuccess('Your payment has been accepted.');

preventDuplicates

When set to true, prevents the display of multiple toast notifications with the same message.

Default ⇒ false

toastr()->preventDuplicates(bool $preventDuplicates = true);
#/ toastr preventDuplicates

toastr()
    ->preventDuplicates(true)
    ->addInfo('Your password has been reset and a new one has been sent to your email.');

progressBar

When set to true, displays a progress bar in the toast.

Default ⇒ true

toastr()->progressBar(bool $progressBar = true);
#/ toastr progressBar

toastr()
    ->progressBar(false)
    ->addWarning('Your password may not have been set.');

rtl

When set to true, displays the toast notifications in right-to-left mode.

Default ⇒ false

toastr()->rtl(bool $rtl = true);
#/ toastr rtl

toastr()
    ->rtl(true)
    ->addInfo('تم قفل حسابك وتم إرسال رسالة تأكيد إلكترونية.');

tapToDismiss

When set to true, the toast can be dismissed by tapping on it.

toastr()->tapToDismiss(bool $tapToDismiss = true);
#/ toastr tapToDismiss

toastr()
    ->tapToDismiss(true)
    ->addWarning('Warning: Proceed with caution.');

target

The element that should contain the toast notifications.

Default ⇒ body

toastr()->target(string $target);
#/ toastr target

toastr()
    ->target('body')
    ->addWarning('Your account may not have been suspended.');

timeOut

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

toastr()->timeOut(int $timeOut, bool $extendedTimeOut = null);
#/ toastr timeOut

toastr()
    ->timeOut(1000) // 1 second
    ->addInfo('This may take some time. Do not refresh the page.');
Younes

PHPFlasher is a project by Younes KHOUBZA.