0
votes

i am new to laravel and trying to play with different aspects of this framework.Currently i am working with route::filters and wrote a simple code to see how filters works.But i am getting the following error:

BadMethodCallException in Macroable.php line 81: Method filter does not exist.

why is this error thrown ?how i can solve this issue? Here is my code in route.php :

Route::filter('birthday', function()
{
    if (true) {
        return View::make('birthday');
    }
});
Route::get('/', array(
    'before' => 'birthday',
    function()
    {
       return View::make('welcome');
    }
));
1
which laravel version you are using?Imtiaz Pabel
i am currently using version 5.2.10AL-zami

1 Answers

3
votes

route filters are not going away entirely after Laravel 5.0 However, middleware is now the preferred way to achieve the same functionality. See http://laravel.com/docs/master/middleware for info about how to use it. Middleware can be implemented to behave like either "before" or "after" filters. And it can be applied to all routes (called "global middleware"), or assigned to specific routes (by adding "'middleware' => 'auth'" for example to your route definitions in your routes.php file.