Are you sure the id of the table is called academic_id. By default, this field is called id and you can use your resource to rename it if you wish.
Dec 2, 2019
7
Level 50
Property [academic_id] does not exist on this collection instance
Hi
I am using an API resource. I am getting this error in collection instance
$timetables = TimetableResource::collection(DB::table('time_tables')
->whereIn('academic_id', $ids)
->whereIn('class', $classid)->get()->groupBy('day'));
and my TimetableResource file
public function toArray($request)
{
return [
'academic_id' => $this->academic_id,
'day' => $this->day,
'class' => Course::find($this->class),
'subject' => Subject::find($this->subject),
'teacher' => Teacher::find($this->teacher),
'timeslot' => $this->timeslot
];
}
Level 102
If you absolutely must then this might work
$timetables = DB::table('time_tables')
->whereIn('academic_id', $ids)
->whereIn('class', $classid)->get()->groupBy('day')->map(function($group) {
return TimetableResource::collection($group);
});
Please or to participate in this conversation.