路由[登录]未定义 [英] Route [login] not defined

查看:85
本文介绍了路由[登录]未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天第一次尝试与Laravel一起玩.尝试访问localhost/project/public时出现以下错误:

Trying to play with Laravel today for the first time. I am getting the following error when I attempt to visit localhost/project/public:

InvalidArgumentException
路由[登录]未定义.

InvalidArgumentException
Route [login] not defined.

app/routes.php:

app/routes.php:

<?php

Route::get('/', 'HomeController@redirect');
Route::get('login', 'LoginController@show');
Route::post('login', 'LoginController@do');
Route::get('dashboard', 'DashboardController@show');

app/controllers/HomeController.php:

app/controllers/HomeController.php:

<?php

class HomeController extends Controller {

    public function redirect()
    {
        if (Auth::check()) 
            return Redirect::route('dashboard');

        return Redirect::route('login');
    }

}

app/controllers/LoginContoller.php:

app/controllers/LoginContoller.php:

<?php

class LoginController extends Controller {

    public function show()
    {
        if (Auth::check()) 
            return Redirect::route('dashboard');

        return View::make('login');
    }

    public function do()
    {
        // do login
    }

}

app/controllers/DashboardController.php:

app/controllers/DashboardController.php:

<?php

class DashboardController extends Controller {

    public function show()
    {
        if (Auth::guest()) 
            return Redirect::route('login');

        return View::make('dashboard');
    }

}

为什么会出现此错误?

推荐答案

您正尝试重定向到命名路由,其名称为login,但是您没有该名称的路由:

You're trying to redirect to a named route whose name is login, but you have no routes with that name:

Route::post('login', [ 'as' => 'login', 'uses' => 'LoginController@do']);

第二个参数的'as'部分定义了路由的名称.第一个字符串参数定义其 route .

The 'as' portion of the second parameter defines the name of the route. The first string parameter defines its route.

这篇关于路由[登录]未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆