Reputation: 1672
I don't want to login users after registration but redirect them login page. So far i am successful overriding Register() in RegisterController.
public function Register(Request $request)
{
$validator = $this->validator($request->all());
if ($validator->fails()) {
$this->throwValidationException(
$request, $validator
);
}
return redirect('/login')->with('message','Successfully Registered');
}
But the success message is not appearing. And when i return directly to view:
return view('auth.login')->with('message','Successfully registered');
The messsage is displayed correctly in login page but the url goes to /register
this means after i try to login, it goes to registration form instead? What is the actual solution to do this?
Upvotes: 4
Views: 11585
Reputation: 597
From Laravel 5.4 you can override the registered()
method in your RegisterController
to flash the message to the session.
/**
* The user has been registered.
*
* @param \Illuminate\Http\Request $request
* @param mixed $user
* @return mixed
*/
protected function registered(Request $request, $user)
{
$request->session()->flash('notification', 'Thank you for subscribing!');
}
Then you can display the message in the view with the session()
helper.
@if (session()->has('notification'))
<div class="notification">
{!! session('notification') !!}
</div>
@endif
Upvotes: 3
Reputation: 3725
Firstly give this flash before the redirect in the Register function :
session()->flash('success', 'You have Successfully Registered');
return redirect('/login');
Then put the below statement to get the message in the view :
{{Session::get('success')}}
Upvotes: 1
Reputation: 3050
Flash to the session:
$request->session()->flash('message', 'content');
Then check if the session exists with:
session()->has('message')
and if it does display it with session()->get('message')
Upvotes: 3
Reputation: 3547
Write this code in the view where this message must display:
{{ Session::get('message'`) }}
Upvotes: 2