Laravel 4:保护控制器提供的路由 [英] Laravel 4: protecting routes provided by a controller
本文介绍了Laravel 4:保护控制器提供的路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在构建Laravel 4应用程序,我想保护自己的管理区域,因此只有在用户登录/验证后才能访问该区域.
I'm building a Laravel 4 app and I want to protect my admin area so it is only accessible if the user is logged in/authenticated.
做到这一点的最佳方法是什么?
What is the best way to do this?
Laravel文档说您可以保护这样的路线:
The Laravel docs say you can protect a route like this:
Route::get('profile', array('before' => 'auth', function()
{
// Only authenticated users may enter...
}));
但是当我的路线看起来像这样时会发生什么:
But what happens when my route looks like this:
Route::resource('cms', 'PostsController');
如何保护指向控制器的路由?
How do I protect a route that is directing to a controller?
提前谢谢!
推荐答案
您可以使用路由组.
例如:
Route::group(array('before' => 'auth'), function()
{
Route::get('profile', function()
{
// Has Auth Filter
});
Route::resource('cms', 'PostsController');
// You can use Route::resource togehter with
// direct routes to the Resource Controller
// so e.g. Route::post('cms', 'PostsController@save');
});
这篇关于Laravel 4:保护控制器提供的路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文