Seems like you forgot to terminate your query
return PromotionCollection::collection($promotions->get());
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi All,
Simple API resource and give me an error
"message": "Undefined property: Illuminate\\Database\\Query\\Builder::$id",
Controller Code
return PromotionCollection::collection($promotions);
AND PromotionCollection
public function toArray($request)
{
return [
'id' => $this->id,
];
}
@tayyabshahzad1 Make a json resource, and use that. In the resource you define what columns you want. https://laravel.com/docs/9.x/eloquent-resources#generating-resources
return PromotionResource::collection($promotions);
Please or to participate in this conversation.