Level 61
I've never used it that way. I've paginated in the controller and passed that result to the resource.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I'm using one API resource file to send data and inside that file I want to send collection on paginate resource. But I cant get only Attributes what I need it getting this error.
"message": "Undefined property: Illuminate\Pagination\LengthAwarePaginator::$id",
this is my two resources files
CourierCashBookResourceWithBal
class CourierCashBookResourceWithBal extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
//return parent::toArray($request);
return [
'balance' => $this->balance,
'TotalCr' => $this->cr,
'TotalDr' => $this->dr,
'items' => new CourierCashBookResource(tblCourierCashBook::with('courier')->paginate()),
];
}
}
CourierCashBookResource
class CourierCashBookResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
//return parent::toArray($request);
return [
'id' => $this->id,
'nickName' => $this->courier->nickName,
'des' => $this->des,
'cr' => $this->cr,
'dr' => $this->dr,
];
}
}
thank you..
Please or to participate in this conversation.