PHP code example of tokiya / laraflash

1. Go to this page and download the library: Download tokiya/laraflash library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tokiya / laraflash example snippets


class UserController
{
    public function store()
    {
        // …

        flash('User successfully registered!');

        return redirect()->back();
    }
}

class UserController
{
    public function store()
    {
        // …

        flash('User successfully registered!');

        return redirect()->back();
    }
}

class UserController
{
    public function store()
    {
        // …

        flash('User successfully registered!')->success();

        return redirect()->back();
    }
}

class UserController
{
    public function store()
    {
        // …

        $flash = flash();
        if (...) {
            $flash->success('Pattern 1 message.');
        } else {
            $flash->success('Pattern 2 message.');
        }

        return redirect()->back();
    }
}

flash('User successfully registered!')->success();
flash('Unregistered information is available.')->warning();
flash('User registration failed.')->error();
flash('A notice exists.')->info();

flash('Please check now.!')->urgent(); // By John

flash('Please check now.!')->emergency(); // By Mary

flash()->customizeErrorKey('danger')->error();

class MyFlash extends Flash
{
    protected array $level_keys = [
        'success' => 'success',
        'warning' => 'warning',
        'error'   => 'danger',
        'info'    => 'info',
    ];
}

flash()->setDefaultSuccessMessage('Successfully saved!')
    ->setDefaultErrorMessage('Failed to save.');

flash()->success(); // Successfully saved!
flash()->error(); //Failed to save.