| Install | |
|---|---|
composer require jambasangsang/flash |
|
| Latest Version: | v1.0.1 |
Flash Notification Types:
Quick Installation using composer.
Run:
composer require jambasangsang/flash
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,
];
php artisan vendor:publish --provider='Jambasangsang\Flash\FlashNotificationServiceProvider' --tag="flash-config"
php artisan vendor:publish
And select Jambasangsang\Flash\FlashNotificationServiceProvider
CSS
@flashStyle,
JS
@jQuery,
@flashScript,
@flashRender
Example:
<!-- layouts/app.blade.php -->
<!doctype html>
<html>
<head>
@flashStyle
</head>
<body>
@jQuery
@flashScript
@flashRender
</body>
</html>
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!')// 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',
],
];
MIT