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('Your item has been added to your cart, but may not be reserved until checkout.');
}
}
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.
Prevent from Auto Hiding.
toastr()->persistent();
#/ toastr persistent
toastr()
->persistent()
->closeButton()
->addWarning('Your question may not have been submitted.');
When set to true
, a close button is displayed in the toast notification.
toastr()->closeButton(bool $closeButton = true);
#/ toastr closeButton
toastr()
->closeButton(true)
->addInfo('Your order has been shipped and a tracking number has been sent to your email.');
The HTML content of the close button.
Default ⇒ <button type="button">×</button>
toastr()->closeHtml(string $closeHtml);
#/ toastr closeHtml
toastr()
->closeButton(true)
->closeHtml('⛑')
->addError('There was a problem registering your device.');
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)
->addError('There was an issue un-terminating your account.');
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.');
When set to true
, new toast notifications are displayed above older ones.
Default ⇒ true
toastr()->newestOnTop(bool $newestOnTop = true);
#/ toastr newestOnTop
toastr()
->newestOnTop(true)
->addWarning('Your account may not have been un-suspended.');
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 contact may not have been added.');
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 application has been received.');
When set to true
, displays a progress bar in the toast.
Default ⇒ true
toastr()->progressBar(bool $progressBar = true);
#/ toastr progressBar
toastr()
->progressBar(false)
->addInfo('This may take some time. Do not refresh the page.');
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('تم قفل حسابك وتم إرسال رسالة تأكيد إلكترونية.');
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 feedback has been submitted and is being reviewed.');
The element that should contain the toast notifications.
Default ⇒ body
toastr()->target(string $target);
#/ toastr target
toastr()
->target('body')
->addSuccess('Your account has been restored.');
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 a problem reinstating your account.');