Home > database >  How to extract two fields into array Laravel?
How to extract two fields into array Laravel?

Time:10-31

Here is a table with two fields: startitime, endtime. I pull out data using:

ScheduleModel::all();

It returns me a data collection. How to get result in plain array like this: [starttime1, endtime1, starttime1, endtime2...]

I have tried to use pluck() but it returns me an array with (key => value) instead plain array.

CodePudding user response:

Try this:

$scheduleVal = ScheduleModel::all();
$scheduleTime = array();

foreach ($scheduleVal as $schedule) {
    array_push($scheduleTime, $schedule->starttime, $schedule->endtime);
}

dd($scheduleTime);
  • Related