I have this form:
<form action="{{route('login')}}" id="loginForm" method="POST">
<div class="text-center" style="font-size: 30px; font-family: 'Poppins', sans-serif;">Login</div><br />
<div class="input-group">
<span class="input-group-label"><i class="fa fa-envelope"></i></span>
<input class="input-group-field" id="lemail" name="lemail" placeholder="Insert your email" type="email" required>
</div>
<p class="help-text" id="email">Type in your email and password to log in.</p>
<div class="input-group">
<span class="input-group-label"><i class="fa fa-lock"></i></span>
<input class="input-group-field" id="lpassword" name="lpassword" placeholder="Type in your password" type="password" required>
</div>
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<br />
<div class="align-center">
<button type="submit" class="button secondary align-center" href="#">Login</button>
</div>
</form>
As you see, I have action="{{route('login')}}"
as I want to use that route:
Route::post('/', [
'as' => 'login',
'uses' => 'LoginUser@login'
]);
And this is the function:
public function login(Request $request)
{
$this->validate($request, [
'lemail' => 'required|string|email|max:255',
'lpassword' => 'required|string|min:6|max:128',
]);
$email = $request->input('lemail');
$password = $request->input('lpassword');
if (Auth::attempt(['email' => $email, 'password' => $password])) {
// Authentication passed...
return redirect()->intended('/home')
->with('flash_notice', 'You are successfully logged in.');
}
return redirect()->intended('/')
->with('flash_error', 'Your username/password combination was incorrect.');
}
The problem is that after I fill the fields and send the form, it tells me that the email and password fields are empty, but they are not.
This only happens if I set the "action" and do the route like that, otherwise it works fine.
I did this because I have it in the footer and I want it to work on all pages, but I can't get it to work.