Laravel - Displaying message data passed to a view Laravel - Displaying message data passed to a view laravel laravel

Laravel - Displaying message data passed to a view


To display the message you should use session:

{{ session('message') }}

You can find out more here


You won't be able to send variables , but you can flash some session data.

enter image description here If you need to keep your flash data around for several requests, you may use the reflash method, which will keep all of the flash data for an additional request.

To store data in session :

$request->session()->put('message', 'project successfully created');return redirect('/projects');

to get that data in the view :

 {{ session('message') }}


To return message passed in a view in laravel, you have to do the below procedure

@if($message = Session::get('message')){<div class="alert alert-success">   <p>{{$message}}</p></div>}

the session is getting the message you passed in to the view and displaying it on the relevant page.

for me, if ii have to pass the message to the view, i normally do it in this way

return redirect()->route('/project')->with('message', 'project successfully created');