请问 Auth::routes ();扩展出来的那些路由你是从哪里找到的?在哪个文件里?

请问Auth::routes();扩展出来的那些路由你是从哪里找到的?在哪个文件里?

《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
最佳答案

可以一点一点找到

Auth::routes(); 这个是调用的是一个 叫 Authalias,见 config/app.php

'aliases' => [

        'App' => Illuminate\Support\Facades\App::class,
        'Artisan' => Illuminate\Support\Facades\Artisan::class,
        'Auth' => Illuminate\Support\Facades\Auth::class,

找到 Illuminate\Support\Facades\Auth 这个门面,可以看到里面有个 routes 方法

public static function routes()
    {
        static::$app->make('router')->auth();
    }

可以看到,它实例化了一个 Router 类,然后再找到这个 Router 类,Illuminate/Routing/Router.php

找到 Illuminate/Routing/Router.php, 里面有个 auth 方法,见内容,应该就明白了吧

public function auth()
    {
        // Authentication Routes...
        $this->get('login', 'Auth\LoginController@showLoginForm')->name('login');
        $this->post('login', 'Auth\LoginController@login');
        $this->post('logout', 'Auth\LoginController@logout')->name('logout');

        // Registration Routes...
        $this->get('register', 'Auth\RegisterController@showRegistrationForm')->name('register');
        $this->post('register', 'Auth\RegisterController@register');

        // Password Reset Routes...
        $this->get('password/reset', 'Auth\ForgotPasswordController@showLinkRequestForm')->name('password.request');
        $this->post('password/email', 'Auth\ForgotPasswordController@sendResetLinkEmail')->name('password.email');
        $this->get('password/reset/{token}', 'Auth\ResetPasswordController@showResetForm')->name('password.reset');
        $this->post('password/reset', 'Auth\ResetPasswordController@reset');
    }

因为命令的使用位置不同,将 $this-> 换成 Route:: 就可以了

5年前 评论
讨论数量: 5

可以一点一点找到

Auth::routes(); 这个是调用的是一个 叫 Authalias,见 config/app.php

'aliases' => [

        'App' => Illuminate\Support\Facades\App::class,
        'Artisan' => Illuminate\Support\Facades\Artisan::class,
        'Auth' => Illuminate\Support\Facades\Auth::class,

找到 Illuminate\Support\Facades\Auth 这个门面,可以看到里面有个 routes 方法

public static function routes()
    {
        static::$app->make('router')->auth();
    }

可以看到,它实例化了一个 Router 类,然后再找到这个 Router 类,Illuminate/Routing/Router.php

找到 Illuminate/Routing/Router.php, 里面有个 auth 方法,见内容,应该就明白了吧

public function auth()
    {
        // Authentication Routes...
        $this->get('login', 'Auth\LoginController@showLoginForm')->name('login');
        $this->post('login', 'Auth\LoginController@login');
        $this->post('logout', 'Auth\LoginController@logout')->name('logout');

        // Registration Routes...
        $this->get('register', 'Auth\RegisterController@showRegistrationForm')->name('register');
        $this->post('register', 'Auth\RegisterController@register');

        // Password Reset Routes...
        $this->get('password/reset', 'Auth\ForgotPasswordController@showLinkRequestForm')->name('password.request');
        $this->post('password/email', 'Auth\ForgotPasswordController@sendResetLinkEmail')->name('password.email');
        $this->get('password/reset/{token}', 'Auth\ResetPasswordController@showResetForm')->name('password.reset');
        $this->post('password/reset', 'Auth\ResetPasswordController@reset');
    }

因为命令的使用位置不同,将 $this-> 换成 Route:: 就可以了

5年前 评论

这个命令我也知道,但是在命令行里面的显示格式不是那样的,不能直接复制粘贴到web.php,有没有原文呢?

5年前 评论

可以一点一点找到

Auth::routes(); 这个是调用的是一个 叫 Authalias,见 config/app.php

'aliases' => [

        'App' => Illuminate\Support\Facades\App::class,
        'Artisan' => Illuminate\Support\Facades\Artisan::class,
        'Auth' => Illuminate\Support\Facades\Auth::class,

找到 Illuminate\Support\Facades\Auth 这个门面,可以看到里面有个 routes 方法

public static function routes()
    {
        static::$app->make('router')->auth();
    }

可以看到,它实例化了一个 Router 类,然后再找到这个 Router 类,Illuminate/Routing/Router.php

找到 Illuminate/Routing/Router.php, 里面有个 auth 方法,见内容,应该就明白了吧

public function auth()
    {
        // Authentication Routes...
        $this->get('login', 'Auth\LoginController@showLoginForm')->name('login');
        $this->post('login', 'Auth\LoginController@login');
        $this->post('logout', 'Auth\LoginController@logout')->name('logout');

        // Registration Routes...
        $this->get('register', 'Auth\RegisterController@showRegistrationForm')->name('register');
        $this->post('register', 'Auth\RegisterController@register');

        // Password Reset Routes...
        $this->get('password/reset', 'Auth\ForgotPasswordController@showLinkRequestForm')->name('password.request');
        $this->post('password/email', 'Auth\ForgotPasswordController@sendResetLinkEmail')->name('password.email');
        $this->get('password/reset/{token}', 'Auth\ResetPasswordController@showResetForm')->name('password.reset');
        $this->post('password/reset', 'Auth\ResetPasswordController@reset');
    }

因为命令的使用位置不同,将 $this-> 换成 Route:: 就可以了

5年前 评论

关键是怎么从router 找到 Illuminate/Routing/Router.php?除了单步调试。大家还有什么好办法?

4年前 评论
vmarsed 2年前

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!