I have the following question. Is it correct to create a dynamic route to return my views, or do I have to create a route for each controller and return the proper view?
Example of the code I'm using
route file
Route::get('/{url?}/{url2?}/{url3?}', 'UrlController@getUrl');
controller
public function getUrl($url = null, $url2 = null, $url3 = null) {
if (isset($url3)) {
return view($url . '.' . $url2 . '.' . $url3);
} elseif (isset($url2)) {
return view($url . '.' . $url2);
} elseif (isset($url)) {
return view($url, ['name' => 'Romullo']);
} else {
return view('home');
}
}
This code returns me exactly the view that is typed in the url or generates the error page correctly. But the doubt arose among so many articles that I read. Is that correct or not? Should I actually create route by route for each controller and view or can I dynamically call?