Example #1
0
 /**
  * Inserts data into the current table. If an object is provided,
  * it will attempt to convert it to an array.
  *
  * @param $data
  *
  * @return bool
  */
 public function insert($data)
 {
     // Must be called first so we don't
     // strip out created_at values.
     $data = $this->doProtectFields($data);
     if ($this->useTimestamps && !array_key_exists($this->createdField, $data)) {
         $data[$this->createdField] = $this->setDate();
     }
     if (empty($data)) {
         throw new \InvalidArgumentException('No data to insert.');
     }
     // Must use the set() method to ensure objects get converted to arrays
     $return = $this->builder()->set($data)->insert();
     if (!$return) {
         return $return;
     }
     return $this->db->insertID();
 }