0

我的 routes.php 中有这段代码

Route::group(["before" => "guest"], function()
{
Route::any("/", [
"as" => "user/login",
"uses" => "UserController@loginAction"
]);
Route::any("/login", [
"as" => "login",
"uses" => "UserController@loginAction"
]);
Route::any("/request", [
"as" => "user/request",
"uses" => "UserController@requestAction"
]);
Route::any("/reset", [
"as" => "user/reset",
"uses" => "UserController@resetAction"
]);
});
Route::group(["before" => "auth"], function()
{
Route::any("/dashboard", [
"as" => "user/dashboard",
"uses" => "UserController@dashboardAction"
]);
Route::any("/users", [
"as" => "users",
"uses" => "UsersController@indexAction"
]);
Route::any("/calculations", [
"as" => "calculations",
"uses" => "CalculationsController@indexAction"
]);
Route::any("/help", [
"as" => "help",
"uses" => "GeneralController@helpAction"
]);
Route::any("/contact-us", [
"as" => "contact-us",
"uses" => "GeneralController@contactUsAction"
]);
Route::any("/settings", [
"as" => "user/settings",
"uses" => "SettingsController@indexAction"
]);
Route::any("/logout", [
"as" => "user/logout",
"uses" => "UserController@logoutAction"
]);
});

我想将尝试访问访客页面的经过身份验证的用户重定向到另一个页面,我该怎么做?我正在使用 Laravel 4

4

2 回答 2

0

您可以通过自定义同一文件夹中的 filters.php 文件来实现。

于 2013-09-16T14:00:32.513 回答
0

创建auth您已经在您的组中引用的过滤器,filters.php如下所示:

Route::filter('auth', function()
{
    // Auth::guest() returns true if user is not logged in:
    if (Auth::guest())  
    {
        return Redirect::action('UserController@loginAction');
    }
});

我在这里猜测UserController@loginAction指向您的登录页面.. :)

Laravel 文档中的更多内容:http: //laravel.com/docs/security#authenticating-users

于 2013-09-16T14:35:34.483 回答