如何为Laravel全局过滤器定义异常路由? [英] How to define exception route for laravel global filter?

查看:122
本文介绍了如何为Laravel全局过滤器定义异常路由?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想运行一个过滤器,以检查是否安装了应用程序,然后再运行除安装相关路由以外的任何路由,因为这将导致无限重定向循环.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆