update into multiple tables 'admission' and 'admission_details'

Posted 6 months ago by tanveerkhanwd

my controller:

    {
        $fval =  (json_encode($_POST['fval']));
        $mval = (json_encode($_POST['mval']));
        $admission = Admission::find($id);
        $admission->name = $request->name;
       $admission->dob = $request->dob;
       $admission->address = $request->address;
      $admission->city = $request->city;
       $admission->state = $request->state;
      $admission->country = $request->country;
      $admission->pincode = $request->pincode;
       $admission->present_school = $request->present_school;
       $admission->grade = $request->grade;
        $admission->join_grade = $request->join_grade;
       $admission->year = $request->year;
        $admission->nationality = $request->nationality;
        $admission->type = $request->type;
        $admission->admissionDetail->father_details = $request->fval;
        $admission->admissionDetail->mother_details = $request->mval;
        $admission->admissionDetail->passport_type = $request->passport_type;
        $admission->admissionDetail->heard_from = $request->heard_from;
        $admission->save();
        return redirect()->route('admin.admission.index')->with('success','Admission Updated successfully');
    }```


my Admission model:

```public function admissionDetail()
    {
         return $this->hasone('App\Models\AdmissionDetail', 'admission_id');
    }```

Please sign in or create an account to participate in this conversation.