A
A
Artur Shalohin2017-05-21 00:51:49
JSON
Artur Shalohin, 2017-05-21 00:51:49

Laravel how to make many records in 1 table with 1 controller request?

Hello! I will be very grateful for your help.
There is an array of objects on the client, I make an ajax post request to the server and I get an error:
Error: Request failed with status code 500

This is how the method to which the route leads

public function setDataCalendar(Request $request)
{
foreach ($request as $dec) {
DecisionTask: :create([
'hours' => $dec->hours,
'date' => $dec->date,
'id_task' => $dec->task_id
]);
}
}

all passed data is correct.

when transferring the 1st object, I removed foreach and changed $dec to $request and the REQUEST WORKED.

What is the problem, who knows?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Finsh, 2017-05-22
@Finsh

Print out dd($request) it's not an array or a collection. To get the contents of $request, you need to call its all() method. It is very likely that you are not transmitting data correctly, I vanguy that there is not an array.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question