예제 #1
0
 public function format($array)
 {
     if (!is_array($array)) {
         throw new \InvalidArgumentException('The resource must be an array.');
     }
     return parent::format($array);
 }
 public function format($entity)
 {
     if (!$entity instanceof Model && !$entity instanceof Collection) {
         throw new \InvalidArgumentException('The resources must be an instance of an Eloquent Model or an Eloquent Collection');
     }
     if (is_null($this->type)) {
         $this->setTypeFromObject($entity);
     }
     if ($entity instanceof Model) {
         return parent::format($entity);
     }
     $formattedResources = [];
     foreach ($entity as $item) {
         $formattedResources[] = parent::format($item);
     }
     return $formattedResources;
 }