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()->addSuccess('Your account has been restored.');
    }
} 

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()
    ->addSuccess('Your password has been changed.');

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 password may be at risk.');

closeHtml

The HTML content of the close button.

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

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

toastr()
    ->closeButton(true)
    ->closeHtml('⛑')
    ->addSuccess('Your account has been suspended.');

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 password has been reset and a new one has been sent to your email.');

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 a problem re-verifying your account.');

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')
    ->addWarning('Your account may not have been restored.');

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)
    ->addSuccess('Your order has been shipped.');

progressBar

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

Default ⇒ true

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

toastr()
    ->progressBar(false)
    ->addError('There was an issue restoring your account.');

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)
    ->addInfo('Your information has been saved and a confirmation email has been sent.');

target

The element that should contain the toast notifications.

Default ⇒ body

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

toastr()
    ->target('body')
    ->addSuccess('Your order has been shipped.');

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
    ->addError('There was an issue unlocking your account.');
Younes

PHPFlasher is a project by Younes KHOUBZA.