2014-04-08 32 views
0

相同的标题,我用我的庄网页时希望所有的人,必须登录(看起来像FB或Twitter,...)与一些要求如下:过滤器使用的网站之前登录 - Laravel框架

  • 如果当前URL是'/'(主页),则系统显示已注册的接口。 (显示而不是重定向)

  • 如果如不同的URL“/”(主页),系统重定向到登录页面。

有人可以帮我吗?我正在使用laravel框架。

+1

如果你只是谷歌'laravel filter',第一个结果就是你所需要的东西。 – hndr

回答

0

Laravel使用名为电源滤波器的事情。

您可以在任何途径使用它们:: 行动你想要的。

不过有点为例五月帮助你。

按照您的要求:

// Check manualy if user is logged. If so, redirect to the dashboard. 
// If not, redirect to the login page 
Route::get('/', function() 
{ 
    if (Auth::check()) // If user is logged 
     return View::make('dashboard') 
    return View::make('/login'); 
} 

// Each routes inside this Route::group will check if the user is logged 
// Here, /example will only be accessible if you are logged 
Route::group(array('before'=>'auth', function() 
{ 
    // All your routes will be here 
    Route::get('/example', function() 
    { 
    return View::make('contents.example'); 
    } 
}); 

当然,过滤器AUTH是建立在Laravel。你可以在app/filters.php 找到这个文件,并根据你的需求进行修改。 如下:

Route::filter('auth', function() 
{ 
    if (Auth::guest()) return Redirect::guest('/login'); 
}); 
+0

如果某些评论(that_guy)或答案(我)不...回答你的问题,不要忘记接受一种或另一种让人们知道有一个解决方案。 – ChainList