Monday, April 3, 2017

Laravel: Skip some params from route or call Controller@show without adding 'static' adding

Laravel: 5.4

It works, But I want to know if there are other pro-solutions.

I have a route like this

Route::get('{any}-a{id}', function($any, $id) {
   return ArticleController::show($id);
})->where(['id' => '[0-9]+', 'any' => '.*']);

But this required public **static** function show($id)

Are there any other solution to call non-static function from Route, or just skip the $any params like ->compact('id') (in Route), or: Route::get('#something-I-don't-know#-a{id}'), function(**$id**) { ... })?

I want to keep the non-static show function because it come from Route:resource of another Route: route('articles.show',$article->id). I don't want to add the $any param.

Thanks for your time and your answers :D



via Onfealive

Advertisement