I have input fields which submit in this manner: dental_plan[property_name] and I can fetch them in controller by doing $request->dental_plan. When I return the request, I get 5 fields which I am sending through. Since DB schema is made so that dental plan has to have patient ID, I need a way to add that property to dental_plan[] but these solutions seem to be failing:
$request['dental_plan']['patient_id'] = $patient->id;
array_push($request->dental_plan, ['patient_id' => $patient->id];
I have tried several other solutions by flipping attributes, getting them as object etc. Usually I get the error Indirect modification of overloaded property Illuminate\Http\Request has no effect. What is the right way to do this?
EDIT:
Is it possible to add one specific and one general field in Laravel model so that you can so something like this:
MyModel::create([['specific_field' => $spec], $request->all()]);