/** * Fills out an instance of the model * and saves it, pretty much like mass assignment. * * @param array $attributes * @return Illuminate\Database\Eloquent\Model */ public function fillAndSave($attributes) { $this->model->fill($attributes); $this->model->save(); return $this->model; }
public function fill(array $attributes) { // if ((empty($fillable) or count($fillable) === 0) and (empty(static::$rules) or count(static::$rules) === 0)) if (!isset(static::$rules)) { return parent::fill($attributes); } // we have rules, proceed $this->validateVars = array(); foreach ($attributes as $key => $value) { // $key = $this->removeTableFromKey($key); if ($this->isFillable($key)) { if (ends_with($key, '_at') and strpos($value, '-')) { switch ($key) { case 'expires_at': $this->validateVars[$key] = strtotime($attributes[$key] . ' 23:59:59'); break; case 'starts_at': $this->validateVars[$key] = strtotime($attributes[$key] . ' 00:00:00'); break; default: $this->validateVars[$key] = strtotime($attributes[$key] . ' 00:00:00'); break; } } elseif (ends_with($key, '_at')) { $timestamp = $attributes[$key]; if ((int) $timestamp === $timestamp and $timestamp <= PHP_INT_MAX and $timestamp >= ~PHP_INT_MAX) { // already a timestamp $this->validateVars[$key] = $timestamp; } else { $format = ci()->settings->date_format; $validated = \DateTime::createFromFormat($format, $timestamp); if ($validated) { $this->validateVars[$key] = $validated->getTimestamp(); } } } else { $this->validateVars[$key] = $attributes[$key]; } } } return parent::fill($this->getValidateVars()); }