Skip to content

Instantly share code, notes, and snippets.

@danielmorgan
Last active January 25, 2017 09:06
Show Gist options
  • Save danielmorgan/217e644926696c93bff0f24d8cbf0fcc to your computer and use it in GitHub Desktop.
Save danielmorgan/217e644926696c93bff0f24d8cbf0fcc to your computer and use it in GitHub Desktop.
Move auth routes to userland code in Laravel 5.3
# routes/auth.php
<?php
/**
* Auth routes copied from Illuminate\Routing\Router::auth()
*/
// Authentication Routes...
Route::get('login', 'LoginController@showLoginForm')->name('login');
Route::post('login', 'LoginController@login');
Route::post('logout', 'LoginController@logout');
// Registration Routes...
Route::get('register', 'RegisterController@showRegistrationForm');
Route::post('register', 'RegisterController@register');
// Password Reset Routes...
Route::get('password/reset', 'ForgotPasswordController@showLinkRequestForm');
Route::post('password/email', 'ForgotPasswordController@sendResetLinkEmail');
Route::get('password/reset/{token}', 'ResetPasswordController@showResetForm');
Route::post('password/reset', 'ResetPasswordController@reset');
# app/providers/RouteServiceProvider.php
<?php
namespace App\Providers;
use Illuminate\Support\Facades\Route;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
class RouteServiceProvider extends ServiceProvider
{
/**
* This namespace is applied to your controller routes.
*
* In addition, it is set as the URL generator's root namespace.
*
* @var string
*/
protected $namespace = 'App\Http\Controllers';
/**
* @var string
*/
protected $authNamespace = 'App\Http\Controllers\Auth';
/**
* Define your route model bindings, pattern filters, etc.
*
* @return void
*/
public function boot()
{
//
parent::boot();
}
/**
* Define the routes for the application.
*
* @return void
*/
public function map()
{
$this->mapApiRoutes();
$this->mapWebRoutes();
$this->mapAuthRoutes();
}
/**
* Define the "web" routes for the application.
*
* These routes all receive session state, CSRF protection, etc.
*
* @return void
*/
protected function mapWebRoutes()
{
Route::group([
'middleware' => 'web',
'namespace' => $this->namespace,
], function ($router) {
require base_path('routes/web.php');
});
}
/**
* Define the "auth" routes for the application.
*
* @return void
*/
protected function mapAuthRoutes()
{
Route::group([
'middleware' => 'web',
'namespace' => $this->authNamespace,
], function ($router) {
require base_path('routes/auth.php');
});
}
/**
* Define the "api" routes for the application.
*
* These routes are typically stateless.
*
* @return void
*/
protected function mapApiRoutes()
{
Route::group([
'middleware' => 'api',
'namespace' => $this->namespace,
'prefix' => 'api',
], function ($router) {
require base_path('routes/api.php');
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment