Laravel过滤器未执行

I have a very weird problem.

On my local machine (Windows 8, XAMPP) the Laravel filters work as they should, but on the server they don't. (Ubuntu with Apache).

Route::filter('test_filter', function($request) {
    echo 'Inside filter<br />';
});

Route::get('test_server2', array('before' => 'test_filter', function() {
    return 'After filter<br />';
}));

When I run this from my local server, the output is:

Inside filter
After filter

When I run the same script from the web, I get:

After filter

As you can see, the filter is not being applied. They are never executed. It's not a random or temporary thing.

I noticed this problem in a large application that I have. I created this simple code to check if the basic stuff works, but it doesn't.

Does anyone know why filters may not be executed?

I've checked the routing classes in the source code of Laravel and I haven't found anything that might help to solve my issue.

First: always define what specific version of Laravel you are using, and where everything is executed.

Some code is executed on production only. If you defined your filter in app/start/artisan.php or app/start/local.php it will not reflect when you execute your application on a server with environment set to production. We are unable to help if you do not exactly specify where your lines of code are defined.

Last but not least: try to reduce the differences between your development environment and your production environment. I recommend using Vagrant and possibly even Laravel Homestead. That way you can develop Laravel applications on Windows and run in a virtual Ubuntu environment.

Hope this helps.

The user Matt Burrow was right. Filters are not executed when the environment is called "testing". I had to change it to something different in order to get them working.

When your application is in 'testing' mode, the route filters are disabled. Because testing is reserved for Unit Testing.

I found it on this issue