For this, you will use Middleware.
Middleware
Middleware provides a mechanism for filtering HTTP requests on
its application. For example, Laravel includes a middleware that
checks if the user of your application is authenticated. If the user
is not authenticated, middleware will redirect the user
to the login tab. However, if the user is authenticated,
middleware will allow the request to proceed further in its application.
Auth Middleware
The Laravel already comes with some middleware for you to use, and one of them is the auth
. You can apply this middleware in various ways.
Specific Route
Assigning the middleware route via fluent method.
Route::get('admin/posts/create', function () {
//
})->middleware('auth');
Route Group
Assigning middleware to a group of routes.
Route::middleware(['auth'])->group(function () {
Route::get('admin/posts/create', function () {});
Route::get('admin/user/profile', function () {});
});
Via Controller
You can assign directly to the controller as well.
class PostsController extends Controller
{
public function __construct()
{
// Nesse caso o middleware auth será aplicado a todos os métodos
$this->middleware('auth');
// mas, você pode fazer uso dos métodos fluentes: only e except
// ex.: $this->middleware('auth')->only(['create', 'store']);
// ex.: $this->middleware('auth')->except('index');
}
}
Read: https://answall.com/questions/119043/comoreredirecionar-o-usu%C3%A1rio-autenticado-para-uma-p%C3%A1gina-espec%C3%Adfica
– novic
Read: https://answall.com/questions/154386/routes-laravel-5-3/154413#154413
– novic