mercredi 18 mai 2016

Laravel route cache on custom route files

I'm building a project in Laravel 5.2 which had a big (big as in a lot of lines) routes.php. To make the routes a little cleaner for the eyes, I've split all the route groups intro separated files. In app\Http\Routes\.

I require all the files in the RouteServiceProvider which works (correction: worked..) perfectly fine for me. After all this I wanted to cache the routes with php artisan route:cache. Then if you went to a page all you get is a 404 error.

“Long” story short: New route logic is crashing AFTER artisan route cache.

This is my map function in RouteServiceProvider (inspired by this answer):

public function map(Router $router)
{
    $router->group(['namespace' => $this->namespace], function ($router) {
        // Dynamically include all files in the routes directory
        foreach (new \DirectoryIterator(app_path('Http/Routes')) as $file)
        {
            if (!$file->isDot() && !$file->isDir() && $file->getFilename() != '.gitignore')
            {
                require_once app_path('Http/Routes').DS.$file->getFilename();
            }
        }
    });
}

Does someone know what the problem is? Or do I just need to put everything back in routes.php if I want to use route caching. Thanks in advance.



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

Aucun commentaire:

Enregistrer un commentaire