dimanche 4 mars 2018

Prevent passing prefix as a route parameter to child routes in Laravel 5

How can I prevent the Route prefix from being passed to all the child routes controller functions?

Route::prefix('{locale?}')->middleware(['locale.default', 'locale'])->group(function() {
      Route::get('/car/{id}', [
            'uses' => 'CarController@getCar',
            'as' => 'car',
            'middleware' => 'auth'
        ])->where(['id' => '[0-9]+']);
});

In CarController's getCar() function, the id parameter is getting the locale (en, fr, it) instead of the id of the car being passed.

public function getCar($id)
{
   $car = Car::where('id', $id)->firstOrFail();
}

To fix this, I must do:

public function getCar($locale, $id)
{
   $car = Car::where('id', $id)->firstOrFail();
}

Is there a way to simply prevent the passing of $locale to the child route's controller functions so that I don't have to add $locale as the first parameter to every function?



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

Aucun commentaire:

Enregistrer un commentaire