LARAVEL SUCCESSFUL REGISTRATION REDIRECTING TO LOGIN PAGE
After registration, it will redirect to the login page with a message showing ‘Registered successfully, please login…!”
For this, Add some code snippet in RegisterController.php
public function register(Request $request) { $this->validator($request->all())->validate(); event(new Registered($user = $this->create($request->all()))); return redirect($this->redirectTo)->with('message', 'Registered successfully, please login...!'); }
Also change $redirectTo=’/home’ to /login
protected $redirectTo = '/login';
Add some code in login.blade.php between panel-body and form tags to setup display for the message.
Nb: remember to use correct html tags for div, as they are purposefully removed to display code.
div class=”panel-body”
@if(Session::has(‘message’))
div class=”alert alert-success”
{{ Session::get(‘message) }}
@php
Session::forget(‘message’);
@endphp
/div
@endif
<form class=”form-horizontal” method=”POST” action=”{{ route(‘register’) }}”>
@if(Session::has(‘message’))
div class=”alert alert-success”
{{ Session::get(‘message) }}
@php
Session::forget(‘message’);
@endphp
/div
@endif
<form class=”form-horizontal” method=”POST” action=”{{ route(‘register’) }}”>
Now click the register link from the navigational bar and try registering. After successful registration, you will be redirected to the login page and notified with a “Registration successful” message as one shown in the above picture.
Post a Comment