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
.
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
.
The following is the output of 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
+--------+----------+-------------------------+------+-----------------------------------------------------------
Override with: Route::get('/admin/login', 'Auth\AuthController@showLoginForm'); Route::post('/admin/login', 'Auth\AuthController@login'); Route::get('/admin/logout', 'Auth\AuthController@logout'); Note: Route::auth() automatically handles login, logout and register.
Laravel includes built-in authentication and session services which are typically accessed via the Auth and Session facades. These features provide cookie-based authentication for requests that are initiated from web browsers. They provide methods that allow you to verify a user's credentials and authenticate the user.
In L5.2, all authentication routes are grouped in a route called Route::auth()
.
If you search for the symbol auth()
, you can see the auth() function which contains all the route links.
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.
Edit:
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.
To get a reference:
// 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');
You can call Route::auth()
inside a prefixed group.
Route::group(['prefix' => 'admin'], function() {
Route::auth();
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With