Reputation: 1903
I'm using the build in authentication from laravel. I want to show a logged in flash message. But can't seem to find where to put that.
I've tried to set it in the Authenticate middleware, but that didn't seem to work.
Tried this:
$request->session()->flash('messages', ['message' => ['status' => 'success', 'text' => 'Successfully logged in']]);
And:
Session::flash('messages', ['message' => ['status' => 'success', 'text' => 'Successfully logged in']]);
But: dd(Session::get('messages'))
is empty.
Full example:
public function handle($request, Closure $next)
{
if ($this->auth->guest()) {
if ($request->ajax()) {
return response('Geen toegang.', 401);
} else {
return redirect()->guest('/'.config('constants.cms_path').'/'.config('constants.login_path'));
}
}
Session::flash('message', ['message' => ['status' => 'warning', 'text' => 'Successfully logged in']]);
return $next($request);
}
How to set a flash message for successful login?
EDIT
Message is working but set every time. Only want to set it when logged in once.
Upvotes: 0
Views: 127
Reputation: 111829
If you put it into Authenticate
middleware and use this middleware for url, this middleware is used aach time you run this middleware and this is what you don't want.
You need to add flashing message in action where user logs in (probably in Controller)
Upvotes: 1
Reputation: 1061
use Session;
Add this line to access session class
Set your Session in controller
Session::flash('message', "Colon Success");
And print your session inside view
<?php
if (Session::has('message')){
echo Session::get('message') ;
}
?>
Upvotes: 1