laravel 5.3 new Auth::routes()
Auth::routes()
is just a helper class that helps you generate all the routes required for user authentication. You can browse the code here https://github.com/laravel/framework/blob/5.3/src/Illuminate/Routing/Router.php instead.
Here are the routes
// 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');
$this->post('password/email', 'Auth\ForgotPasswordController@sendResetLinkEmail');
$this->get('password/reset/{token}', 'Auth\ResetPasswordController@showResetForm');
$this->post('password/reset', 'Auth\ResetPasswordController@reset');
Laravel 5.3 auth routes redirecting to /
Just found the cause.
It's in the RedirectIfAuthenticated
Middleware:
if (Auth::guard($guard)->check()) {
return redirect('/');
}
Understanding Auth::routes() after php artisan make:auth
The RegisterController
uses a trait named Illuminate\Foundation\Auth\RegistersUsers
in which you will find your register()
method.
Check out in the Laravel's source code here.
Read more about trait here.
Laravel 5.3 Direct Home URI to Auth in Routes?
About 5 minutes after posting this, I realized I needed to do this:
Route::get('/', function () {
return view('auth.login');
});
Auth::routes();
Route::get('/home', 'HomeController@index');
Laravel 5.3 routes one url 2 controllers middleware
You can create new middleware:
<?php
namespace App\Http\Middleware;
use Closure;
class isGuest
{
public function handle($request, Closure $next)
{
if (! \Auth::check()) {
return redirect('/guest-page');
}
return $next($request);
}
}
Then you need to register the new middleware in the app/Http/Kernel.php
protected $routeMiddleware = [
'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
];
And then just attach it to the needed routes:
Route::get('user', [
'uses' => 'UsersController@index',
'as' => 'users.index'
])->middleware('isGuest');
You can also use several middleware for one route:
Route::get('user', [
'uses' => 'UsersController@index',
'as' => 'users.index'
])->middleware('isGuest', 'secondMiddleware' ...);
More information here: https://laravel.com/docs/5.3/middleware#global-middleware
Related Topics
Laravel - Decryptexception: 'The MAC Is Invalid'
Admin Product Pages Custom Field Displayed in Cart and Checkout
What Is the Name for the "<<<" Operator
How to Get Attribute of Node with Namespace Using Simplexml
MySQL & PHP Parameter 1 as Resource
How to Sort a Multidemensional Array by an Inner Key
Get the Values of 2 HTML Input Tags Having the Same Name Using PHP
Looping a SQL Insert Statement with Dates
Differencebetween the | and || Operators
What Does It Mean to Run PHP in Quiet Mode
Detect If Uploaded File Is Too Large
Simple Xml Add Namespaced Child
How to Find Timezone Id from Ip Address/Country Name in PHP