如何为Laravel全局过滤器定义异常路由? [英] How to define exception route for laravel global filter?
问题描述
我想运行一个过滤器,以检查是否安装了应用程序,然后再运行除安装相关路由以外的任何路由,因为这将导致无限重定向循环.
I want to run a filter that check if application is installed or not, before running any route except installation related routes, cause it would cause an infinite redirect loop.
这是我应该做的:
Route::filter('before', function()
{
if (!User::isInstalled()) {
return Redirect::to_route('install'); // infinite redirect loop
}
});
是否有任何方法可以向此过滤器添加例外?或以任何方式检查当前女巫路线是否正在运行? 任何的想法? 谢谢
Is there any way to add exception to this filter? or any way to check that currently witch route is running? any idea? thanks
推荐答案
我从 laravel API,Laravel \ Routing \ Route 可能是一个解决方案
I found this method from laravel api, Laravel\Routing\Route that could be a solution
Route::filter('before', function()
{
if ( ! Application::isInstalled() && ! URI::is('install*') ) {
return Redirect::to_route('install');
}
});
但是我认为它们应该是强制某些路由在过滤器之前不使用的更好方法.
感谢 bstrahija
but I think they should be better way to force some routes to not use before filter.
thanks to bstrahija
这篇关于如何为Laravel全局过滤器定义异常路由?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!