Reputation: 10135
I'm trying to display some flash messages, after I have successfully logged in. Can somebody help me understand why nothing is shown ?? Although I know the Session is true?`
This is my Sessions Controller:
class SessionsController extends \BaseController {
public function create()
{
return View::make('sessions.create');
}
public function store()
{
$attempt = Auth::attempt([
'email' => $input['email'],
'password' => $input['password']
]);
if($attempt) return Redirect::intended('/')->with('flash_message', 'You have been logged in!');
dd('problem');
}
public function destroy()
{
Auth::logout();
return Redirect::home();
}
}
And here is my view where the message should be displayed:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Yes</title>
</head>
<body>
<main>
@if(Session::get('flash_message'))
<div class="flash">
{{ Session::get('flash_message') }}
</div>
@endif
<div class="container">
@yield('content')
</div>
</main>
</body>
</html>
I also tried this:
@if(Session::get('flash_message'))
<div class="flash">
{{ Session::get('flash_message') }}
</div>
@else
<div class="flash">
{{ Session::get('flash_message') }}
</div>
@endif
But nothing get's displayed, just an empty nothingness, just like no message was parsed to the view.
Thanks for helping me out :)
Upvotes: 1
Views: 948
Reputation: 3664
In your store
function, before if
you should add:
Session::flash('flash_message', 'You have been logged in!');
This is used to store flash data in session. The with
method won't work in a way you intend.
And then in view:
@if(Session::has('flash_message'))
{{ Session::get('flash_message') }}
@endif
Upvotes: 1