1

There is a controller method:

public function addEducation(AddPatientEducationRequest $request) {

    dd($request->all());

    $state = UserEducation::create($request->validated());
}

The dd() returns me an array that I need to insert into db:

array:1 [ // app\Http\Controllers\Api\PatientController.php:99
  "education" => array:1 [
    0 => array:5 [
      "patient_id" => 1
      "education_id" => 2
      "diplom" => "ZV 800"
      "start_date" => "2021-10-30"
      "end_date" => "2022-10-30"
    ]
  ]
]

I tried this way using loop:

foreach($request->education as $value) { UserEducation::create($value); }

0

2 Answers 2

1

Your content looks like this:

[
    'education' => [
        //some fields
    ]
]

So, you can reach your record like this:

myArray['education'][0]

, hence your script should be

foreach($request['education'] as $value) {
    UserEducation::create($value);
}
Sign up to request clarification or add additional context in comments.

Comments

1

If education multidimensional array matches database columns then you can use the insert method like below

UserEducation::insert($request->education)

Ref :Insert Statements

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.