Open knnhcn opened 6 years ago
Please post your Admin/LoginController's
code. I'll try to help you.
Hi there, thank you for your offer. Here is my AdminLoginController:
<?php
namespace App\Http\Controllers\Auth;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Auth;
class AdminLoginController extends Controller
{
public function __construct()
{
$this->middleware('guest:admin', ['except' => ['logout']]);
}
public function showLoginForm()
{
return view('auth.admin-login');
}
public function login(Request $request)
{
// Validate the form data
$this->validate($request, [
'email' => 'required|email',
'password' => 'required|min:6'
]);
// Attempt to log the user in
if (Auth::guard('admin')->attempt(['email' => $request->email, 'password' => $request->password], $request->remember)) {
// if successful, then redirect to their intended location
return redirect()->intended(route('admin.dashboard'));
}
// if unsuccessful, then redirect back to the login with the form data
return redirect()->back()->withInput($request->only('email', 'remember'));
}
public function logout()
{
Auth::guard('admin')->logout();
return redirect('/');
}
}
It seems fine.
What can be causing the bug:
$error->has('email') ? 'has-error' : ''
in <div class="form-group">
You should paste the admin login view here.
Furthermore, try to go into this step by step created by me: https://medium.com/@renandiett/laravel-5-4-trabalhando-com-autentica%C3%A7%C3%B5es-independentes-sem-packages-adicionais-6e50c11a0b79
If you do not understand Portuguese, I suggest you to use a translator like Google.
I had the same issue and it's because of this line:
return redirect()->back()->withInput($request->only('email', 'remember'));
To resolve this I followed the same paradigm of the AuthenticatesUsers
trait:
protected function sendFailedLoginResponse(Request $request)
{
throw ValidationException::withMessages([
$this->username() => [trans('auth.failed')],
]);
}
I did all the tutorials and it works fine. But I have the problem, that admin login form does not show errors when for example entering a wrong e-mail addresse. The user login form shows the errors, but the admin login not.