## Usage
PHPFlasher provides a simple and intuitive way to add notifications to your application. You can use either the `flash()` helper function or inject the `FlasherInterface` through dependency injection.
{% assign id = '#/ PHPFlasher' %}
{% assign type = 'success' %}
{% assign message = site.data.messages[type] | sample %}
{% assign options = '{}' %}
{% include example.html %}
```php
{{ id }}
// Using the helper function
flash()->success('{{ site.data.messages["success"] | sample }}');
// Or using dependency injection
use Flasher\Prime\FlasherInterface;
class BookController
{
public function store(FlasherInterface $flasher)
{
// Save the book...
$flasher->success('{{ message }}');
return redirect()->back();
}
}
```
Choose a clear message that tells the user what happened. For example, `"Book has been created successfully!"` is a good message, but you can adjust it to fit your application's context and language.
> This package is easy to use. You can add notifications to your application with just 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()`, and `info()` — are shortcuts for the `flash()` method. They let you specify the `type` and `message` in one method call instead of passing them separately to `flash()`.
```php
flash()->flash(string $type, string $message, array $options = [], string $title = null)
```
{% 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 }}');
```
| Parameter | Description |
|------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `$type` | Notification type: success, error, warning, info |
| `$message` | The message you want to show to the user. This can include HTML. If you add links, make sure to add the right classes for your framework. |
| `$title` | The notification title. Can also include HTML. |
| `$options` | Custom options for JavaScript libraries (toastr, noty, notyf, etc.). |
---