Example #1
0
 public function create($data = [])
 {
     try {
         //instantiates a new entity
         $entity = $this->factory->newEntity($data);
         //validade the entity
         if (!$this->filter->forInsert($entity)) {
             return $this->payload->notValid([$this->entityName => $entity, 'messages' => $this->filter->getMessages()]);
         }
         //insert the entity
         if (!$this->gateway->create($entity)) {
             return new $this->payload->notCreated([$this->entityName => $entity]);
         }
         //success
         return $this->payload->created([$this->entityName => $entity]);
     } catch (\Exception $e) {
         return $this->payload->error(['exception' => $e, 'data' => $data]);
     }
 }