🇵🇸 Solidarity with Palestine. We seek justice and peace, and strongly oppose all forms of injustice and genocide.

If you find PHPFlasher useful, please consider giving it a ⭐ star on GitHub 😊. If you spot any typos or have suggestions, feel free to contribute to the documentation 📝. Your feedback helps keep the project up-to-date and well-maintained. Thank you


Laravel

Installation

composer require php-flasher/flasher-toastr-laravel

After installation, you need to run another command to set up the necessary assets for PHPFlasher:

php artisan flasher:install

Configuration

Note: The configuration settings below are the default ones. You only need to change them if you want to customize the default behavior.

<?php // config/flasher.php

return [
    'plugins' => [
        'toastr' => [
            '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
            ],
        ],
    ],
];


Symfony

Installation

composer require php-flasher/flasher-toastr-symfony

After installation, you need to run another command to set up the necessary assets for PHPFlasher:

php bin/console flasher:install

Configuration

Note: The configuration settings below are the default ones. You only need to change them if you want to customize the default behavior.

# 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 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.

success

#/ noty

use Flasher\Toastr\Prime\ToastrInterface;

class BookController
{
    public function saveBook()
    {        
        toastr()->success('Your account has been re-verified.');
        
        // or simply 
        
        toastr('Your account has been re-verified.');
    }
    
    /**
     * if you prefer to use dependency injection 
     */
    public function register(ToastrInterface $toastr)
    {
        // ...

        $toastr->success('Your device has been registered.');

        // ... redirect or render the view
    }
}

info

#/ usage info

toastr()->info('Your report has been generated and a confirmation email has been sent.');

warning

#/ usage warning

toastr()->warning('Your subscription may not have been cancelled.');

error

#/ usage error

toastr()->error('Error!');

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 notyf adapter.


persistent

Prevent from Auto Hiding.

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

toastr()
    ->persistent()
    ->closeButton()
    ->error('There was a problem shipping your order.');

closeButton

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

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

toastr()
    ->closeButton(true)
    ->success('Your payment has been accepted.');

closeHtml

The HTML content of the close button.

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

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

toastr()
    ->closeButton(true)
    ->closeHtml('⛑')
    ->info('Your email has been verified and a confirmation email has been sent.');

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

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)
    ->error('<strong>We’re sorry</strong>, but an error occurred.');
#/ toastr escapeHtml true

toastr()
    ->escapeHtml(true)
    ->error('<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)
    ->info('Your order has been placed and is being processed.');

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')
    ->success('Your review has been submitted.');

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)
    ->error('There was an issue confirming your reservation.');

progressBar

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

Default ⇒ true

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

toastr()
    ->progressBar(false)
    ->success('Your address has been updated.');

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)
    ->info('تم قفل حسابك وتم إرسال رسالة تأكيد إلكترونية.');

tapToDismiss

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

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

toastr()
    ->tapToDismiss(true)
    ->info('Your password has been changed 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')
    ->success('The operation was successful.');

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
    ->warning('Your subscription may not have been cancelled.');
Younes

PHPFlasher is a project by Younes ENNAJI.