[英]laravel allowing only authenticated user to access a specific route
I have already read this in the official documentation: 我已经在官方文档中阅读了以下内容:
Protecting A Route 保护路线
Route::get('profile', array('before' => 'auth', function()
{
// Only authenticated users may enter...
}));
but i couldn't know how to apply it in my case. 但是我不知道如何在我的情况下应用它。
This is my routes.php 这是我的routes.php
Route::get('/', function()
{
return View::make('hello');
});
Route::get('index', function()
{
return View::make('index');
});
Route::get('restaurants/admins/{id}', 'RestaurantsController@admins');
Route::resource('restaurants', 'RestaurantsController');
Route::post('admins/login', array('uses' => 'AdminsController@login', 'as' => 'admins.login'));
Route::post('admins/changePicutre', array('uses' => 'AdminsController@changePicture', 'as' => 'admins.changePicture'));
Route::resource('admins', 'AdminsController');
Route::resource('waitingtimes', 'WaitingtimesController');
Route::post('restaurants/changePicture', array('uses' => 'RestaurantsController@changePicture', 'as' => 'restaurants.changePicture'));
Route::get('login', function(){
return View::make('admins.login');
});
I need all the routes to be only for authenticated users except the loing
route. 我需要所有的路线是只针对除通过认证的用户
loing
路线。
could you help me please? 请问你能帮帮我吗?
many thanks 非常感谢
Use the Route::group()
in order to protect all the routes inside the group with the filter, like so: 使用
Route::group()
以便通过过滤器保护组内的所有路由,如下所示:
// All routes in the group are protected, only authed user are allowed to access them
Route::group(array('before' => 'auth'), function() {
Route::get('restaurants/admins/{id}', 'RestaurantsController@admins');
});
// Login, all users allowed
Route::get('login', function(){
return View::make('admins.login');
});
Route::get('yourRoutes', array('before' => 'auth', function()
{
// Only authenticated users may enter...
}));
Route::get('routes',array('before'=>'auth','as'=>'namedRoute','uses'=>'controller');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.