app/Http/Resources/AccountResource.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)
    {
        if ($this->resource->relationLoaded("contact")) {
            return [
                "id" => $this->contact->id,
                "name" => $this->contact->name,
                "type" => $this->contact->type,
                "gender" => $this->contact->gender,
                "dob" => $this->contact->dob,
                "phone_number" => $this->contact->phone,
                "email" => $this->contact->email,
                "address" => $this->contact->address,
                "city" => $this->contact->city,
                "state" => $this->contact->state,
                "pincode" => $this->contact->pincode,
                "created_by" => $this->contact->created_by,
                "account" => $this->accountArray(),
            ];
        } else {
            return
                $this->accountArray();
        }
    }
public function toArray ( $ request ) { if ( $ this -> resource -> relationLoaded ( " contact " ) ) { return [ " id " => $ this -> contact -> id , " name " => $ this -> contact -> name , " type " => $ this -> contact -> type , " gender " => $ this -> contact -> gender , " dob " => $ this -> contact -> dob , " phone_number " => $ this -> contact -> phone , " email " => $ this -> contact -> email , " address " => $ this -> contact -> address , " city " => $ this -> contact -> city , " state " => $ this -> contact -> state , " pincode " => $ this -> contact -> pincode , " created_by " => $ this -> contact -> created_by , " account " => $ this -> accountArray ( ) , ] ; } else { return $ this -> accountArray ( ) ; } }
Transform the resource into an array.
Transform the resource into an array .