Laravel 5.1 路线未定义

Laravel 5.1 Route not defined

我正在用 Laravel 5.1 开发一个网络应用程序,我开始进行用户身份验证,我将此路由添加到 routes.php 文件:

Route::get('auth/login', 'Auth\AuthController@getLogin');
Route::get('auth/register', 'Auth\AuthController@getRegister');
Route::get('auth/logout', 'Auth\AuthController@getLogout');
Route::post('auth/login', 'Auth\AuthController@postLogin');
Route::post('auth/register', 'Auth\AuthController@postRegister');

如果我在 url 栏中输入 link 它会起作用,但如果我输入模板,则语法如下:

<a href="{{ URL::route('auth/register') }}">Registra't</a>

我收到错误路线 [auth/register] 未定义。我做错了什么?还有什么事要做吗?

URL::route() 期待一个命名路由,在这里你应该使用 URL::to() 或者你可以创建一个命名路由

Route::get('auth/register', [
  'as' => 'register', 
  'uses' => 'Auth\AuthController@getRegister'
]);

然后用URL::route('register')到link到路线auth/register

因为您还没有定义命名路由并且 URL::route 接受路由名称作为它的第一个参数。您刚刚定义了一个路径 auth/register.

要定义命名路由,您可以这样做:

Route::post('auth/register', [
   'as' => 'auth/register', 'uses' => 'Auth\AuthController@postRegister'
]);

随便放 Auth::routes();routes/web.php

当我使用 auth0 tutorial

时,这对我有用
php artisan cache:clear
php artisan view:clear
php artisan route:clear
php artisan config:clear

为我工作,放置 "as" 并调用路由,例如:

Route::get('auth/logout', ['as' => 'auth/logout','uses'=>'Auth\AuthController@getLogout']);

以及 HTML: y para el HTML:

 <li><a href="{{route('auth/logout')}}">Logout</a></li> 

这个解决方案在 Laravel 5.1

对我有用