PHP code example of jambasangsang / flash

1. Go to this page and download the library: Download jambasangsang/flash 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/ */

    

jambasangsang / flash example snippets


'providers' => [
    Jambasangsang\Flash\FlashNotificationServiceProvider::class,
];




namespace App\Http\Controllers;

use App\Http\Requests\LevelStoreRequest;
use App\Models\Level;
use Illuminate\Http\RedirectResponse;
use App\Jambasangsang\Services\Levels\LevelService;
use Jambasangsang\Flash\Facades\LaravelFlash;

class LevelController extends Controller
{

    public function store(LevelStoreRequest $request, LevelService $levelService): RedirectResponse
    {
       
       try{
            $levelService->storeLevelData(new Level(), $request);

            LaravelFlash::withSuccess("Level added successfully!");

       }catch{

            LaravelFlash::withError("Woops!! an error check your input and try again!");
       }
        
        return redirect()->route('levels.index');
    }
}


// config/flash.php


return [

    'options' => [
        'message'       => 'Default Message Here', //String
        'messageTextColor'   => '#ffff', //String
        'position'        => 'top-right', //String
        'customClass'     => '', //String
        'width'       => 'auto', //String Ex. 190px etc.
        'showCloseButton'         => true, //Boolean
        'closeButtonText'       => 'Close', //String
        'alertScreenReader'      => true, //Boolean
        'duration'       => 5000,
        'onClose'        => 'el', // Write your custom function here
        'closeButtonTextColor'      => '#FFFF',
    ],
];


sh
php artisan vendor:publish --provider='Jambasangsang\Flash\FlashNotificationServiceProvider' --tag="flash-config"
sh
 php artisan vendor:publish