Php 在路由中使用可选参数
我想在两个场景中使用相同的路线Php 在路由中使用可选参数,php,laravel,Php,Laravel,我想在两个场景中使用相同的路线 使用不传递参数的路由 使用带有参数的路由 那么,这有可能吗&如何做到呢?在Web Php中 You can optional parameters like this Route::get('my-method/{param?}', function ($param= null) { // your code here }); Route::get('find-services/{service_name?}', 'commonController@find_
You can optional parameters like this
Route::get('my-method/{param?}', function ($param= null) {
// your code here
});
Route::get('find-services/{service_name?}', 'commonController@find_services')->name('find-services');
并在commonController.php中处理参数
public function find_services($service_name = null) {// Do something here}
或使用get方法检查控制器中的参数
public function find_services() {
$input = Request::all();
if (isset($input['service_name']) AND ! empty($_GET['service_name'])) {
// Code
}
}
我希望这篇文章能有所帮助,如需有关Web Php的更多信息,请点击这里=>
Route::get('find-services/{service_name?}', 'commonController@find_services')->name('find-services');
并在commonController.php中处理参数
public function find_services($service_name = null) {// Do something here}
或使用get方法检查控制器中的参数
public function find_services() {
$input = Request::all();
if (isset($input['service_name']) AND ! empty($_GET['service_name'])) {
// Code
}
}
我希望这一条有帮助,有关更多信息,请参见这里=>是的,使用get方法是的,使用get方法