--- permalink: /library/notyf/ title: Notyf description: Add lightweight, customizable notification messages to your web projects with Notyf, a popular JavaScript library. With a focus on simplicity and accessibility, Notyf is easy to install and use, making it a great choice for any project that wants to engage and inform users. handler: notyf data-controller: notyf --- ## Laravel
```shell composer require php-flasher/flasher-notyf-laravel ``` After installation, you need to run another command to set up the necessary assets for PHPFlasher: ```shell php artisan flasher:install ``` ```php [ 'notyf' => [ 'scripts' => [ '/vendor/flasher/flasher-notyf.min.js', ], 'styles' => [ '/vendor/flasher/flasher-notyf.min.css', ], 'options' => [ // Optional: Add global options here 'dismissible' => true, ], ], ], ]; ``` ## Symfony ```shell composer require php-flasher/flasher-notyf-symfony ``` After installation, you need to run another command to set up the necessary assets for PHPFlasher: ```shell php bin/console flasher:install ``` ```yaml # 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](/installation/#-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. {% assign id = '#/ noty' %} {% assign type = 'success' %} {% assign message = site.data.messages[type] | sample %} {% assign options = '{}' %} {% include example.html %} ```php {{ id }} use Flasher\Notyf\Prime\NotyfInterface; class BookController { public function saveBook() { notyf()->success('{{ message }}'); // or simply notyf('{{ message }}'); } /** * if you prefer to use dependency injection */ public function register(NotyfInterface $notyf) { // ... $notyf->success('{{ site.data.messages["success"] | sample }}'); // ... redirect or render the view } } ``` {% assign id = '#/ usage info' %} {% assign type = 'info' %} {% assign message = site.data.messages[type] | sample %} {% assign options = '{}' %} {% include example.html %} ```php {{ id }} notyf()->{{ type }}('{{ message }}'); ``` {% assign id = '#/ usage warning' %} {% assign type = 'warning' %} {% assign message = site.data.messages[type] | sample %} {% assign options = '{}' %} {% include example.html %} ```php {{ id }} notyf()->{{ type }}('{{ message }}'); ``` {% assign id = '#/ usage error' %} {% assign type = 'error' %} {% assign message = site.data.messages[type] | sample %} {% assign options = '{}' %} {% include example.html %} ```php {{ id }} notyf()->{{ type }}('{{ message }}'); ``` --- For more information on Notyf options and usage, please refer to the original documentation at [https://github.com/caroso1222/notyf](https://github.com/caroso1222/notyf) --- > The methods described in the **[Usage](/installation/#-usage)** section can also be used with the `notyf` adapter. --- Viewport location where notifications are rendered position x ⇒ `left`, `center`, `right`