I have a simple app, I need to pass two different ID's id
and code_id
in a route, here is my solution I have tried so far
view
<a href="{{ route('settings.code', $settings->id, $settings->code_id) }}">{{ __('Code') }}</a>
Here is route config
Route::get('settings/code/{id}/{code_id}', ['as' => 'settings.code', 'uses' => 'SettingController@code']);
Here is my function in a controller
public function code($code_id, $id)
{
$settings = Setting::find($code_id, $id);
dd($settings);
return view('pages.settings.code', compact('settings'));
}
Here is the error I get
Missing required parameters for [Route: settings.code] [URI: settings/code/{id}/{code_id}]. (0)
What is wrong with my code?
First you should pass an array as 2nd argument to route()
method:
{{ route('settings.code', ['id' => $settings->id, 'code_id' => $settings->code_id]) }}
And note that:
Route parameters are injected into route callbacks / controllers based on their order - the names of the callback / controller arguments do not matter.
So you should swap the arguments of your controller's method:
public function code($id, $code_id)
{
//...
}
I Got My Solution Like This.
Route::match(["get", "post"], "/patient-member-orders/ {patient_id}/{member_id} ", [PathologyController::class, "patientMemberOrders"])->name("pathology-patient-member-orders");
After That We Need To Pass That Name In Our Route Method's Second Argument As An Array In Key Value Pair.
route("pathology-patient-member-orders", ["patient_id" => $member->patient_id, "member_id" => $member->id])
Please Correct Me If I Am Wrong.
Chinmay Mishra Associate Software Developer@Ezdat Technology Pvt. Ltd. Delhi Gurugram.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.