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