Ad
Laravel Adding An Alert To A View
I am trying to add an alert/warning to a view but displaying nothing. I can get my alerts to work with a redirect but wondering how to do it with a view that passes data. Is there a way to pass an alert to a view or is there a "Correct" way of doing this?
$form = new Form();
$form->storeRequest($request);
$form->saveJson();
$form->loadForm($request->cuid, $request->cubaseName);
return view('layouts.pages.form', ['form'=>$form])->with('success', 'Form has been saved.');
//return redirect()->back()->with('success', 'Saved!'); <--this would work if i wasn't passing data
Ad
Answer
All Framework use a special method to send message from controller known as Flash message
In your controller
$request->session()->flash('success', 'Form has been saved');
And to access it on view
@if($message = Session::get("success"))
<h3 class="text-center text-success">{{$message}}</h3>
@endif
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
Ad