Laravel路由传递多个参数,API
Laravel route pass multiple parameters, API
我想调用 link 的几个参数:国家 ID、table ID 和来自 table“名称”的值。
class InsuranceController extends Controller
{
public function index(Request $request)
{
$request->validate([
'name' => '',
'arabic' => '',
'country_id' => '',
]);
$insurances = Insurance::filter($request->all())
->paginate(config('custom.items_per_page'));
return response()->json($insurances);
}
public function getInsurances($country_id)
{
$insurances = Insurance::where('country_id', $country_id)
->paginate(config('custom.items_per_page'));
return response()->json($insurances);
}
}
API路线
Route::get('insurance&country={$countryid}&id={id}&title={name}',
'Api\InsuranceController@getInsurancesFilter')
->name('getInsurancesFilter');
将API路线更改为以下
Route::get('insurance/{county_id}/{id}/{name}', 'Api\InsuranceController@getInsurancesFilter')->name('getInsurancesFilter');
在保险控制器中
public function getInsurances($country_id,$id,$name)
{
$insurances = Insurance::where('country_id', $country_id)->paginate(config('custom.items_per_page'));
return response()->json($insurances);
}
Route::get('insurance&country/{countryid?}/{id?}/{name?}', 'Api\InsuranceController@getInsurancesFilter')->name('getInsurancesFilter');
public function getInsurances($countryId=null,$id=null,$name=null)
{
$insurances = Insurance::where('country_id', $countryId)
->paginate(config('custom.items_per_page'));
return response()->json($insurances);
}
我想调用 link 的几个参数:国家 ID、table ID 和来自 table“名称”的值。
class InsuranceController extends Controller
{
public function index(Request $request)
{
$request->validate([
'name' => '',
'arabic' => '',
'country_id' => '',
]);
$insurances = Insurance::filter($request->all())
->paginate(config('custom.items_per_page'));
return response()->json($insurances);
}
public function getInsurances($country_id)
{
$insurances = Insurance::where('country_id', $country_id)
->paginate(config('custom.items_per_page'));
return response()->json($insurances);
}
}
API路线
Route::get('insurance&country={$countryid}&id={id}&title={name}',
'Api\InsuranceController@getInsurancesFilter')
->name('getInsurancesFilter');
将API路线更改为以下
Route::get('insurance/{county_id}/{id}/{name}', 'Api\InsuranceController@getInsurancesFilter')->name('getInsurancesFilter');
在保险控制器中
public function getInsurances($country_id,$id,$name)
{
$insurances = Insurance::where('country_id', $country_id)->paginate(config('custom.items_per_page'));
return response()->json($insurances);
}
Route::get('insurance&country/{countryid?}/{id?}/{name?}', 'Api\InsuranceController@getInsurancesFilter')->name('getInsurancesFilter');
public function getInsurances($countryId=null,$id=null,$name=null)
{
$insurances = Insurance::where('country_id', $countryId)
->paginate(config('custom.items_per_page'));
return response()->json($insurances);
}