Home > Enterprise >  Laravel route pass multiple parameters, API
Laravel route pass multiple parameters, API

Time:03-21

I want to call several parameters to the link: country id, table id, and value from table "name."

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

Route::get('insurance&country={$countryid}&id={id}&title={name}', 
    'Api\InsuranceController@getInsurancesFilter')
        ->name('getInsurancesFilter');

CodePudding user response:

Change API route to below

  Route::get('insurance/{county_id}/{id}/{name}', 'Api\InsuranceController@getInsurancesFilter')->name('getInsurancesFilter');

In InsuranceController

public function getInsurances($country_id,$id,$name)
    {   
    $insurances = Insurance::where('country_id', $country_id)->paginate(config('custom.items_per_page'));
            return response()->json($insurances);
 }

CodePudding user response:

   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);
    }
  • Related