1

我在这里收到InvalidArgumentException Route [login] not defined错误:

C:\xampp\htdocs\shopping\vendor\laravel\framework\src\Illuminate\Routing\UrlGenerator.php

    /**
     * Get the URL to a named route.
     *
     * @param  string  $name
     * @param  mixed   $parameters
     * @param  bool  $absolute
     * @return string
     *
     * @throws \InvalidArgumentException
     */
    public function route($name, $parameters = [], $absolute = true)
    {
        if (! is_null($route = $this->routes->getByName($name))) {
            return $this->toRoute($route, $parameters, $absolute);
        }

        throw new InvalidArgumentException("Route [{$name}] not defined.");
    }

    /**
     * Get the URL for a given route instance.
     *
     * @param  \Illuminate\Routing\Route  $route
     * @param  mixed  $parameters
     * @param  bool   $absolute
     * @return string
     *
     * @throws \Illuminate\Routing\Exceptions\UrlGenerationException

这是我的路线:

Route::group(['middleware' => ['auth']],function(){
    route::get('/admin/dashboard','AdminController@dashboard');
});

这是我的方法:

public function handle($request, Closure $next, $guard = null)
{
    if (Auth::guard($guard)->check()) {
        return redirect('/home');
    }
    else{
        return redirect()->action('AdminController@login')->with('success','please login to access');
    }

    return $next($request);
}
4

4 回答 4

4

Laravel 有一个php artisan make:auth函数,如果你在终端中运行它,它将为你的应用程序生成 auth 脚手架。

查看此文档https://laravel.com/docs/5.6/authentication

于 2018-04-25T12:36:54.420 回答
2

php artisan make:auth在您的 laravel 应用程序中运行脚手架身份验证。

于 2018-04-25T12:39:55.677 回答
2

清除视图缓存,这可能有效

于 2018-04-25T12:40:50.343 回答
0

在 exception/handler.php 上添加新功能

protected function unauthenticated($request, AuthenticationException $exception){
  if($request->expectsJson()){
    return response()->json(['error' => 'Unauthenticated.'], 401);
  }

  return redirect('/home');
}
于 2020-03-24T02:33:35.027 回答