I am creating a one page website using laravel where I have a login form and a registration form on the same page.
I wish to route them to their respective controller functions, say, AccessController@login
and AccessController@register
respectively. How can I achieve this, when for both the forms the route would be:
Route::post('/', 'ControllerName@function')
It's generally a bad idea, but you can achieve what you want by doing this:
Add <input type="hidden" name="action" value="register">
and <input type="hidden" name="action" value="login">
to signup and login forms accordingly
In controller method check which form was submitted:
$action = Input::get('action');
// handle the register request
if ($action === 'register') {
return $this->register();
// handle the login request
} elseif ($action === 'login') {
return $this->login();
} else {
throw new Exception("Unknown action");
}
I know it is too late. But if anybody looking for this. Why don't you use like this?
first form
<form method="POST" name="login" id="login" action="{{ url('/login') }}">
</form
second form
<form name="register" method="POST" action="{{ url('/register')}}">
</form>
And in your route
Route::post('/login','AuthController@login');
Route::post('/register', 'AuthController@register');