dimanche 5 février 2017

how to migrate and transform laravel 4 filters to laravel 5?

I want to migrate from laravel 4 to laravel 5, and it seems filter concept has been changed in laravel 5.

I have the filter below (and also auth, guest, csrf filters) in app/filters.php file:

Route::filter('date_validation', function ($route, $request) {
    $parameters = $route->parameters();
    if(array_key_exists('date', $parameters)) {
        $date = $parameters["date"];            

        if(strtotime($date) > time() || strtotime($date) < strtotime('2014-01-01')) {
            return Redirect::to('/');
        }

    }

    if(array_key_exists('time', $parameters)) {
        $time = $parameters["time"];

        if($time > '23-59') {
            return Redirect::to('/den');
        }
    }

});

I have defined some routes in routes.php file using this filter like that:

Route::group(array('before' => 'date_validation'), function() {
    // some routes.
});

But now, I see that I should use middleware. I think I should add filters to boot method of App\Providers\RouteServiceProviders class. But how? Could you help me?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2lbnWjP
via IFTTT

Aucun commentaire:

Enregistrer un commentaire