Quantcast
Channel: Laravel 4 how to display flash message in view? - Stack Overflow
Viewing all articles
Browse latest Browse all 12

Answer by Milleus88 for Laravel 4 how to display flash message in view?

$
0
0

two methods:

Method 1 - if you're using

return Redirect::to('users/groups')->withInput()->with('success', 'Group Created Successfully.');

under your controller create(), add in

$success = Session::get('success');
return View::make('viewfile')->with('success', $success);

then on view page,

@if (isset($success))
{{$success }}
@endif

What's happening in method 1 is that you're creating a variable $success that's passed into your create(), but it has no way of display $success. isset will always fail unless you set a variable to get the message and return it.

Method 2 - use return Redirect withFlashMessage

return Redirect::route('users/groups')->withFlashMessage('Group Created Successfully.');

then on your view page,

@if (Session::has('flash_message'))
{{ Session::get('flash_message') }}
@endif

Method 2 is much cleaner and does not require additional code under create().


Viewing all articles
Browse latest Browse all 12

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>