Laravel 9. PHP 8.0.
The task is to write an array line by line. Can you tell me why writing with eloquent in this form does not work, while writing as DB select works fine. What is my problem?
Original code
$task = $request['task'];
$datetask = $request['datetask'];
$timetask = $request['timetask'];
for ($i = 0; $i < count($task ); $i++) {
DB::insert('insert into tasks (task,datetask,timetask,)values(?,?,?)',
[$task[$i],$datetask[$i],$timetask[$i]]);
};
and Eloquent code:
for ($i = 0; $i < count($task); $i++) {
$task= new Task;
$task->task = $request['task'];
$task->datetask = $request['datetask'];
$task->timetask = $request['timetask'];
$task->save();
}
Error:
Array to string conversion.
Line:: $task->save();