John Doe 2 John Doe 2 - 4 months ago 13
PHP Question

Laravel return view show message

How can I show a message after I return a view in my Controller.

I am using Laravel 5.1.

return view('pr.new', [
'errorMessageDuration' => 'error too long',
'route' => 'createPr',
'type' => 'new',
]);


I tried to call the message like this:

@if(session('errorMessageDuration'))
<div class="alert alert-danger">
<a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
{{ session('errorMessageDuration') }}
{{ Input::get('title') }}
</div>
@endif


But it did not work, any ideas?

Answer

Use code Like This

@if(isset($errorMessageDuration))
         <div class="alert alert-danger">
             <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
             {{ $errorMessageDuration }}
             {{ Input::get('title') }}
         </div>
  @endif