This package will send flash notification to your application

v1.0.1 2022-02-21 12:22 UTC

This package is auto-updated.

Last update: 2025-06-21 19:55:40 UTC


README

Issues Latest Version License Stars Total Downloads

Laravel Flash Notification

Flash Notification Types:

Laravel Flash Notification

Installation

Quick Installation using composer.

Run:

 composer require jambasangsang/flash

Then you can add the service provider to config/app.php.

In Laravel versions 5.6 and beyond, this step can be skipped if package auto-discovery is enabled.

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

Publish the configuration file:

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

If not found run the below command:

 php artisan vendor:publish 

And select Jambasangsang\Flash\FlashNotificationServiceProvider

Usage

1. If your application is using jQuery do not include [@jQuery], Otherwise Add the below code in your main view template:

CSS @flashStyle,

JS @jQuery, @flashScript, @flashRender

Example:

<!-- layouts/app.blade.php -->

<!doctype html>
<html>
    <head>
        
        @flashStyle
    </head>

    <body>
        
    @jQuery
    @flashScript
    @flashRender

    </body>
</html>

2. Within your controllers, before you perform a redirection...

Example:

<?php

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');
    }
}

You may also use other options below:

  • LaravelFlash::withInfo('You have pay your bills this week!')
  • LaravelFlash::withSuccess('Your Record has been saved successfully!')
  • LaravelFlash::withWarning('You have an security issue try to fix that!')
  • LaravelFlash::withError('Your Record was not saved Fail!')

configuration:

to customize your flash notification.
// config/flash.php
<?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',
    ],
];

Credits

License

MIT