2 months ago

Router - is it possible to stop sending route parameter to controller action

Posted 2 months ago by Čamo

I have a routes which handles locale parameter like

Route::get( '/{locale}/{book}', '[email protected]' )
			->name( 'book.detail' )
			->where( 'locale', 'en|cz' );

and the BookController with detail action

	public function detail(Book $book) 
		return view('book.detail', [
			'book' => $book,

There are two parameters in the route but I dont want to catch both in controller action. I want only the second one which is slug and which will be instantiated to Book instance via DI.

Also I have a middleware which calls App::setLocale() and then I dont need locale param anymore.

Current state is the router send me both locale and book params to detail method. I would like to have controller actions clean without locale parameters.

Is it possible to remove or stop including locale parameter in the route flow? Or is it possible to call controller::action from route callback with only parameters I need?

Please sign in or create an account to participate in this conversation.