I have a controller that I want to do some logic on a variable and send it to resource to show it in api so here is my controller :
public function index()
{
$data = Accommodation::with('accommodationFacilities')->paginate();
$x = Accommodation::with('cities')->get(1);
return new AccommodationResource($data);
}
and here is the resource :
and now in the resource I want to show the $x in my Api
public function toArray($request)
{
return parent::toArray($request);
}
EDIT
If I want to show the $x data nexto a $data model how can i do it like below :
public function toArray($request)
{
return [
'id' => $this->id,
'X' => $this->x,
];
}
cause right now it gives me the below error :
Undefined property: Illuminate\Pagination\LengthAwarePaginator::$id and when i remove the pagination this error apear :
Call to undefined method Illuminate\Database\Eloquent\Builder::all()
as I tried $x replaces the $data and I can't use the data any more.
->get(1)meant to be->find(1)??