Route [login] not defined

前端 未结 14 1897
無奈伤痛
無奈伤痛 2020-12-02 15:15

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

InvalidArgume

14条回答
  •  悲哀的现实
    2020-12-02 15:45

    Laravel has introduced Named Routes in Laravel 4.2.

    WHAT IS NAMED ROUTES?

    Named Routes allows you to give names to your router path. Hence using the name we can call the routes in required file.


    HOW TO CREATE NAMED ROUTES?

    Named Routes created in two different way : as and name()

    METHOD 1:

    Route::get('about',array('as'=>'about-as',function()
        {
                return view('about');
         }
    ));
    

    METHOD 2:

     Route::get('about',function()
    {
     return view('about');
    })->name('about-as');
    

    How we use in views?

    about-as
    

    Hence laravel 'middleware'=>'auth' has already predefined for redirect as login page if user has not yet logged in.Hence we should use as keyword

        Route::get('login',array('as'=>'login',function(){
        return view('login');
    }));
    

提交回复
热议问题