---
permalink: /installation/
title: Installation
description: Install only the specific components you need for your project with PHPFlasher, a modular PHP library for displaying flash notification messages. Simply include the library in your composer.json file and run the composer install command to get started.
---
**PHPFlasher** is modular and consists of multiple libraries,
allowing users to install and use only the specific components they need for their project.
## Installation
**PHPFlasher** can be installed using composer :
** Laravel**:
```shell
composer require php-flasher/flasher-laravel
```
After installation, you need to run another command to set up the necessary assets for PHPFlasher:
```shell
php artisan flasher:install
```
** Symfony**:
```shell
composer require php-flasher/flasher-symfony
```
After installation, you need to run another command to set up the necessary assets for PHPFlasher:
```shell
php bin/console flasher:install
```
---
## Usage
To display a notification message, you can either use the `flash()` helper method or obtain an instance of `flasher` 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 = '#/ PHPFlasher' %}
{% assign type = 'success' %}
{% assign message = site.data.messages[type] | sample %}
{% assign options = '{}' %}
{% include example.html %}
```php
{{ id }}
use Flasher\Prime\FlasherInterface;
class BookController
{
public function saveBook()
{
// ...
flash('{{ message }}');
flash()->success('{{ site.data.messages["success"] | sample }}');
app('flasher')->success('{{ site.data.messages["success"] | sample }}');
// ... redirect or render the view
}
/**
* if you prefer to use dependency injection
*/
public function register(FlasherInterface $flasher)
{
// ...
$flasher->success('{{ site.data.messages["success"] | sample }}');
// ... redirect or render the view
}
}
```
It's important to choose a message that is clear and concise, and that accurately reflects the outcome of the operation.
In this case, `"Book has been created successfully!"` is already a good message,
but you may want to tailor it to fit the specific context and language of your application.
> Using this package is actually pretty easy. Adding notifications to your application actually require only one line of code.
{% assign id = '#/ usage success' %}
{% assign type = 'success' %}
{% assign message = site.data.messages[type] | sample %}
{% assign options = '{}' %}
{% include example.html %}
```php
{{ id }}
flash()->{{ type }}('{{ message }}');
```
{% assign id = '#/ usage error' %}
{% assign type = 'error' %}
{% assign message = site.data.messages[type] | sample %}
{% assign options = '{}' %}
{% include example.html %}
```php
{{ id }}
flash()->{{ type }}('{{ message }}');
```
{% assign id = '#/ usage warning' %}
{% assign type = 'warning' %}
{% assign message = site.data.messages[type] | sample %}
{% assign options = '{}' %}
{% include example.html %}
```php
{{ id }}
flash()->{{ type }}('{{ message }}');
```
{% assign id = '#/ usage info' %}
{% assign type = 'info' %}
{% assign message = site.data.messages[type] | sample %}
{% assign options = '{}' %}
{% include example.html %}
```php
{{ id }}
flash()->{{ type }}('{{ message }}');
```
---
These four methods (`success`, `error`, `warning`, `info`) are simply convenience shortcuts for the `flash` method,
allowing you to specify the `type` and `message` in a single method call rather than having to pass both as separate arguments to the `flash` method.
```php
flash()->flash(string $type, string $message, string $title = null, array $options = [])
```
{% assign id = '#/ usage flash' %}
{% assign type = site.data.messages.types | sample %}
{% assign message = site.data.messages[type] | sample %}
{% assign options = '{}' %}
{% include example.html %}
```php
{{ id }}
flash()->flash('{{ type }}', '{{ message }}');
```
| param | description |
|------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `$type` | Notification type : success, error, warning, info ....etc |
| `$message` | The body of the message you want to deliver to your user. This may contain HTML. If you add links, be sure to add the appropriate classes for the framework you are using. |
| `$title` | The notification title, Can also include HTML |
| `$options` | Custom options for javascript libraries (toastr, noty, notyf ...etc) | |
---