I am trying to loop through an array of ids to get data from another table, I mean I want to get latest queues of every schedule id we are looping in it.
So first i have $schedules:
$schedules = [{"id":19},{"id":18},{"id":15}]
And the foreach loop is like this:
$queues= [];
foreach ($schedules as $schedule) {
$queues[] = Queue::withTrashed()
->latest()
->where('schedule_id', $schedule);
}
return $queues;
when i return queues it's showing :
Object of class Illuminate\Database\Eloquent\Builder could not be converted to string
$queueses = [];
and then you are using$queues[] = Queue::...
. Is this a typo? Also, you are not running the query, you need a->get()
at the end ofQueue::...->where(...)->get()
– porloscerros Ψ->where('schedule_id', $schedule->id);
– porloscerros ΨTrying to get property 'id' of non-object
. is that suppose to appear? @porloscerrosΨ – Lafoune$schedules
and assigning it the value as it is shown in the question, try doing it this way:$schedules = json_decode('[{"id":19},{"id":18},{"id":15}]');
– porloscerros Ψ