在Laravel 5.2中更改登录/注册URL [英] Change the login/register URL in Laravel 5.2

查看:138
本文介绍了在Laravel 5.2中更改登录/注册URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在编写一个应用程序,该应用程序仅包含公司员工的帐户,而不包含常规的网站访问者的帐户.因此,我想将与网站的管理"区域相关的URL保留在/admin URL下,这意味着将/login更改为/admin/login,将/register更改为/admin/register.

I'm currently writing an application which only has accounts for staff of the company, not regular website visitors. As such, I would like to keep my URLs which relate to the 'admin' area of the site, under the /admin URL which means changing /login to /admin/login and /register to /admin/register.

但是,我对如何在Laravel 5.2中更改登录名和注册URL感到迷惑,似乎在以前的版本中,将protected $loginPath = '/admin/login';添加到Auth\AuthController只是一个简单的问题,但是,这没有什么区别将其添加到我的AuthController时.

However, I'm at a loss as how to change the login and register URLs in Laravel 5.2, it seems that in previous versions it was a simple matter of adding protected $loginPath = '/admin/login'; to Auth\AuthController However, this makes no difference when adding it to my AuthController.

以下是php artisan route:list的输出;

+--------+----------+-------------------------+------+-----------------------------------------------------------
| Domain | Method   | URI                     | Name | Action
+--------+----------+-------------------------+------+-----------------------------------------------------------
|        | GET|HEAD | /                       |      | App\Http\Controllers\PageController@index
|        | GET|HEAD | admin                   |      | App\Http\Controllers\AdminPageController@index
|        | GET|HEAD | admin/profile           |      | App\Http\Controllers\AdminPageController@profile
|        | GET|HEAD | login                   |      | App\Http\Controllers\Auth\AuthController@showLoginForm
|        | POST     | login                   |      | App\Http\Controllers\Auth\AuthController@login
|        | GET|HEAD | logout                  |      | App\Http\Controllers\Auth\AuthController@logout
|        | POST     | password/email          |      | App\Http\Controllers\Auth\PasswordController@sendResetLink
|        | POST     | password/reset          |      | App\Http\Controllers\Auth\PasswordController@reset
|        | GET|HEAD | password/reset/{token?} |      | App\Http\Controllers\Auth\PasswordController@showResetForm
|        | GET|HEAD | register                |      | App\Http\Controllers\Auth\AuthController@showRegistrationF
|        | POST     | register                |      | App\Http\Controllers\Auth\AuthController@register
+--------+----------+-------------------------+------+-----------------------------------------------------------

推荐答案

在L5.2中,所有身份验证路由都分组在名为Route::auth()的路由中.

In L5.2, all authentication routes are grouped in a route called Route::auth().

如果搜索符号auth(),则可以看到包含所有路线链接的auth()函数.

If you search for the symbol auth() , you can see the auth() function which contains all the route links.

检查此文件:Illuminate\Routing\Router用于auth()功能.

Check this file: Illuminate\Routing\Router for the auth() function.

但是我不确定在此处进行更改是否是一个好习惯.

But I'm not sure if it's a good practice to change it here.

因此,如果您需要更改默认的身份验证路由,请包括所有路由 在您的routes.php文件中,然后根据需要更改uri.

So if you need to change the default auth routes, include all routes in your routes.php file and change the uri as you want it.

要获取参考:

    // Authentication Routes...
    Route::get('login', 'Auth\AuthController@showLoginForm');
    Route::post('login', 'Auth\AuthController@login');
    Route::get('logout', 'Auth\AuthController@logout');

    // Registration Routes...
    Route::get('register', 'Auth\AuthController@showRegistrationForm');
    Route::post('register', 'Auth\AuthController@register');

    // Password Reset Routes...
    Route::get('password/reset/{token?}', 'Auth\PasswordController@showResetForm');
    Route::post('password/email', 'Auth\PasswordController@sendResetLinkEmail');
    Route::post('password/reset', 'Auth\PasswordController@reset');

这篇关于在Laravel 5.2中更改登录/注册URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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