Level 46
You can't. Route files aren't the place to handle logic.
Do then handling based on the id in a controller.
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
My Page Table
--------------------------------------------
ID | Page | FunctionName
--------------------------------------------
1 | Home | home
2 | Welcome | wel
Here What i want to achive ---------------->
If user click on link, a page id will pass in route.
e.g. localhost/test/public/page/1
I want to write query in web.php and want to pass $function in controller function. So $function will change everytime whenever there will be new page ID
Route (Web.php)
$function = DB::table('page')->where('id',$id)->pluck('FunctionName');
Route::get('/page/{id}',['uses' => 'HomeController@'$function]);
Please or to participate in this conversation.