app/Http/Resources/OrderResource.php
/**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
     */
Transform the resource into an array.
Transform the resource into an array .
public function toArray($request)
    {
        return [
            'id' =>$this->id,
            'name' => $this->name,
            'email' => $this->email,
            'total' => $this->total,
            'order_items' => OrderItemResource::collection($this->whenLoaded('orderItems'))
        ];
    }
public function toArray ( $ request ) { return [ 'id' => $ this -> id , 'name' => $ this -> name , 'email' => $ this -> email , 'total' => $ this -> total , 'order_items' => OrderItemResource :: collection ( $ this -> whenLoaded ( 'orderItems' ) ) ] ; }
Transform the resource into an array.
Transform the resource into an array .
//attribute compact function call getNameAttribute(order Models) //getTotalAttribute() in model