Presets allow you to use predefined messages

Published at 01 June 2022

If you like PHPFlasher please consider giving it a on github or by spreading the word on twitter. Your support allows me to keep this package up-to-date and maintainable. Thank you


Let’s say you have a custom notification that you want to use in multiple places. You can create a preset for it and then use it in multiple places.

You can think of a preset as a pre-defined message that you can use in multiple places.

For Laravel:

// config/flasher.php
return [
    'default' => 'flasher',
    'presets' => [
        'entity_saved' => [
            'type' => 'success',
            'message' => 'Entity saved successfully',
            'title' => 'Entity saved',
        ],
    ],
];

For Symfony:

# config/packages/flasher.yaml
flasher:
    default: theme.bootstrap
    presets:
        entity_saved:
            type: success
            message: Entity saved successfully
            title: Entity saved

And then use it in your controller:

class BookController
{
    public function save(FlasherInterface $flasher)
    {
        $flasher->addPreset('entity_saved')
Younes

PHPFlasher is a project by Younes KHOUBZA.