Ad

Laravel Adding An Alert To A View

- 1 answer

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

Laravel -> Http Session -> Flash Data

Ad
source: stackoverflow.com
Ad