Я создал пользовательскую защиту (admin) в своем приложении, и все выглядит хорошо после этого онлайн-урока (https://pusher.com/tutorials/multiple-authentication-guards-laravel).). Единственная проблема - когда я пытаюсь получить доступ к представлению, защищенному администратором, вместо этого дает мне исключение NotAuthenticate, дает мне "InvalidArgumentException
Маршрут [логин] не определен. ".
Настраиваемая защита моего контроллера Dashboard:
public function __construct()
{
$this->middleware('auth:admin');
}
Но странная вещь, которую я не могу понять, это то, что, когда я добавляю в мой web.php маршрутизацию "Auth :: маршруты ();", все работает нормально, исключение NotAuthenticate срабатывает.
Есть ли причина, по которой мои пользовательские работы ожидали, когда я добавлю Auth :: route ()?
Контроллер входа администратора:
namespace App\Http\Controllers\Admin\Auth;
use Auth;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Validation\ValidationException;
class LoginController extends Controller
{
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo = '/admin/dashboard';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest:admin')->except('logout');
}
public function login(Request $request)
{
$this->validateLogin($request);
// If the class is using the ThrottlesLogins trait, we can automatically throttle
// the login attempts for this application. We'll key this by the username and
// the IP address of the client making these requests into this application.
if ($this->hasTooManyLoginAttempts($request)) {
$this->fireLockoutEvent($request);
return $this->sendLockoutResponse($request);
}
if ($this->attemptLogin($request)) {
return $this->sendLoginResponse($request);
}
// If the login attempt was unsuccessful we will increment the number of attempts
// to login and redirect the user back to the login form. Of course, when this
// user surpasses their maximum number of attempts they will get locked out.
$this->incrementLoginAttempts($request);
return $this->sendFailedLoginResponse($request);
}
public function showLoginForm()
{
return view('admin.auth.login');
}
/**
* Log the user out of the application.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function logout(Request $request)
{
$this->guard()->logout();
$request->session()->invalidate();
return $this->loggedOut($request) ?: redirect('/admin');
}
/**
* Get the guard to be used during authentication.
*
* @return \Illuminate\Contracts\Auth\StatefulGuard
*/
protected function guard()
{
return Auth::guard('admin');
}
}