I'm a clean guy when I code and I don't like typing the same thing over and over again, so I will try to be simple.
In my Laravel project I have two routes for every major page on the website, for example:
Route::get('/artigos','GlobalController@gestorArtigos');
Route::get('/artigos/{id}','GlobalController@gestorArtigos');
When it receives an ID in the controller:
public function gestorArtigos(Request $request , $id = '') {
$MyOutput = view('artigos.art_gestor_base');
if($id){
return $MyOutput->with('id',$id);
}
return $MyOutput->with('request',$request);
}
This is completely fine and I have no intention of changing this. What does bother me is the fact that I have to repeat the same function every single time I create a new page. The only differences are the function name and the value of $MyOutput
, because the views change.
I need help to compact the function to a 'global' one so I don't have to repeat the code, just call it.