🇵🇸 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-notyf-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' => [
        'notyf' => [
            'scripts' => [
                '/vendor/flasher/flasher-notyf.min.js',
            ],
            'styles' => [
                '/vendor/flasher/flasher-notyf.min.css',
            ],
            'options' => [
                // Optional: Add global options here
                // 'dismissible' => true,
            ],
        ],
    ],
];

Symfony

Installation

composer require php-flasher/flasher-notyf-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:
        notyf:
            scripts:
                - '/vendor/flasher/flasher-notyf.min.js'
            styles:
                - '/vendor/flasher/flasher-notyf.min.css'
            options:
            # Optional: Add global options here
            #    dismissible: 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 notyf() helper method or obtain an instance of notyf 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\Notyf\Prime\NotyfInterface;

class BookController
{
    public function saveBook()
    {        
        notyf()->success('Your form has been submitted.');
        
        // or simply 
        
        notyf('Your form has been submitted.');
    }
    
    /**
     * if you prefer to use dependency injection 
     */
    public function register(NotyfInterface $notyf)
    {
        // ...

        $notyf->success('Your account has been restored.');

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

info

#/ usage info

notyf()->info('Your account has been terminated and a confirmation email has been sent.');

warning

#/ usage warning

notyf()->warning('Your donation may not have been received.');

error

#/ usage error

notyf()->error('There was a problem re-verifying your account.');

For more information on Notyf options and usage, please refer to the original documentation at https://github.com/caroso1222/notyf


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


position

Viewport location where notifications are rendered

position x ⇒ left, center, right
position y ⇒ top, center, bottom

Default ⇒ x: right, y: bottom

notyf()->position(string $position, string $value);
#/ notyf position

notyf()
    ->position('x', 'center')
    ->position('y', 'top')
    ->info('Your account has been suspended and a confirmation email has been sent.');

duration

Number of milliseconds before hiding the notification. Use 0 for infinite duration.

notyf()->duration(int $duration);
#/ notyf duration

notyf()
    ->duration(2000) // 2 seconds
    ->success('The action was completed successfully.');

ripple

Whether to show the notification with a ripple effect

Default ⇒ true

notyf()->ripple(bool $ripple);
#/ notyf ripple true

notyf()
    ->ripple(true)
    ->warning('Your donation may not have been received.');
#/ notyf ripple false

notyf()
    ->ripple(false)
    ->warning('Your donation may not have been received.');

dismissible

Whether to allow users to dismiss the notification with a button

Default ⇒ false

notyf()->dismissible(bool $dismissible);
#/ notyf dismissible

notyf()
    ->dismissible(true)
    ->success('Your subscription has been cancelled.');
Younes

PHPFlasher is a project by Younes ENNAJI.