title: Can I use transformers to transform data coming from API rather than from database?
body: <p>I have been using laravel to build my APIs. I use transformers to tranform data from model object.</p>
  
  <p>Now instead of database, I have a response coming from an API as the data source and I want to transform that data back to a user, but I am unable to do so. </p>
  
  <p><strong>My Controller</strong></p>
  
  <pre><code> public function rocByName(Request $request)
      {
          try {
              $this-&gt;roc_by_name_validator-&gt;with( $request-&gt;all() )-&gt;passesOrFail();
              $company_name = $request-&gt;input('company_name');
              $result = $this-&gt;my_service-&gt;getDetailsByName($company_name); //$result has the response object from the API which I want to transform and give it as a response.
  
               return $this-&gt;response-&gt;collection($result,new OnboardingTransformer()); //Tried using tranformer like this
          }
          catch (ValidatorException $e) {
  
              dd($e);
  
          }
  
      }
  </code></pre>
  
  <p><strong>My Transformer</strong></p>
  
  <pre><code>&lt;?php
  
  namespace Modules\Onboarding\Transformers;
  
  use League\Fractal\TransformerAbstract;
  use App\Entities\OnboardingEntity;  //I dont have an entity since the response is coming from an API!! What will give here?
  
  /**
   * Class OnboardingTransformerTransformer
   * @package namespace App\Transformers;
   */
  class OnboardingTransformer extends TransformerAbstract
  {
  
      /**
       * Transform the \OnboardingTransformer entity
       * @param \OnboardingTransformer $model
       *
       * @return array
       */
      public function transform(OnboardingEntity $data_source) 
      {
          return [
              'company_name'         =&gt; $data_source-&gt;company_name,
          ];
      }
  }
  </code></pre>
  
  <p>Here the OnboardingEntity refers to data coming from database ideally. Here I am not fetching data from database, instead my data is from an API source. How do I go about it. I am little consfused here. Can someone give a solution? </p>
  
  <p>$result has the following response </p>
  
  <pre><code>[
      [
          {
              "companyID": "U72400MHTC293037",
              "companyName": "pay pvt LIMITED"
          },
          {
              "companyID": "U74900HR2016PT853",
              "companyName": "dddd PRIVATE LIMITED"
          }
      ]
  ]
  </code></pre>