/** * @param array $data * @return bool */ public function insert(array $data = []) { $this->source->fill($data); if ($this->source->save()) { return $this->source->getKey(); } return false; }
public function dataForCompany(array $data) { $tes = \DB::table($this->throughTableName)->whereCompanyId($this->companyId)->whereId($this->throughId)->get(); if (empty($tes)) { throw new \Exception('thorugh data not found'); } $foreignId = str_singular($this->throughTableName) . '_id'; $data[$foreignId] = $this->throughId; return $this->model->fill($data); }
/** * Override to ensure uuid is set, so everything can be referenced from that * parameter, rather than from an integer parameter. * * @param array $attributes * * @return $this */ public function fill(array $attributes) { if (empty($attributes['uuid'])) { $attributes['uuid'] = Uuid::uuid4()->toString(); } return parent::fill($attributes); }
/** * */ protected function save() { $data = $this->request->all(); $this->modelItem->getForm()->updateRequestData($data); $rules = $this->modelItem->getForm()->getValidationRules(); $this->instance->validate($data, $rules); $this->instance->fill($data); $this->instance->save(); }
/** * {@inheritDoc} */ public function toModel(Result $result, Model $model) { $exclude = ['location', 'full_address']; $filtered = array_diff_key($result->getSource(), array_flip($exclude)); $model->exists = true; $model->id = $result->getId(); $model->fill($filtered); return $model; }
public function fill(array $attributes) { parent::fill($attributes); if (array_key_exists('slug', $attributes) === false && array_key_exists('title', $attributes)) { // create slug $slugify = new Slugify(); $this->slug = $slugify->slugify($attributes['title']); } return $this; }
/** * Update an exsiting resource. * * @param Request * @param int $id * @return Response */ protected function _update(Request $request, $id) { // Get the resource if it has not been provided by the child class if (!$this->resource->getKey()) { $this->resource = $this->resource->findOrFail($id); } // Transfer input to the resource $this->resource = $this->resource->fill($request->input()); // Save to the storage return $this->save(__FUNCTION__); }
/** * Save file attributes required for interpolation to model * * @param string|Illuminate\Database\Eloquent\Model $model * @param Ideil\LaravelFileOre\Interpolator\InterpolatorResult $input * * @return Illuminate\Database\Eloquent\Model */ protected function saveModelData(Model $model, Interpolator\InterpolatorResult $input) { // prepare data to fill model $model_map = $model->getFileAssignMap(); $model_fields = []; foreach ($input->getData() as $field => $value) { $model_fields[isset($model_map[$field]) ? $model_map[$field] : $field] = $value; } // not save, just fill data $model->fill($model_fields); return $model; }
/** * fill model datas to database * * @param array $datas * @return boolean */ protected function fillModel($datas) { $grouped = collect($datas)->groupBy('relation_type'); foreach ($grouped as $key => $groups) { // no relation if ($key === 'not') { foreach ($groups as $group) { $this->model->fill($group['datas'])->save(); } continue; } // hasOne relation if ($key === 'hasOne') { foreach ($groups as $group) { $relation = $group['relation']; if (is_null($this->model->{$relation})) { $this->model->{$relation}()->save(new $group['relation_model']($group['datas'])); continue; } $this->model->{$relation}->fill($group['datas'])->save(); } continue; } // hasMany relation if ($key === 'hasMany') { foreach ($groups as $group) { $relation = $group['relation']; $relation_models = []; foreach ($group['datas'] as $data) { $relation_models[] = new $group['relation_model']($data); } if (isset($group['is_reset']) && $group['is_reset']) { $this->model->{$relation}()->delete(); } // bu if image banner için eklenmiştir if (isset($group['changeToHasOne']) && $group['changeToHasOne']) { if (is_null($this->model->{$group['changeToHasOne']})) { $this->model->{$group['changeToHasOne']}()->save(new $group['relation_model']($group['datas'][0])); continue; } $this->model->{$group['changeToHasOne']}->fill($group['datas'][0])->save(); continue; } $this->model->{$relation}()->saveMany($relation_models); } continue; } return false; } return true; }
/** * @param Model $model * @param array $rules * @param TransformerAbstract $transformer * @return ResponseFactory */ public function withNewItem($model, $rules, $transformer) { $data = Request::all(); if (isset($data['data'])) { if (is_array($data['data'])) { $data = $data['data']; } } $validator = Validator::make($data, $rules); if ($validator->fails()) { return $this->errorWrongArgsValidator($validator); } $model->fill($data); $model->save(); return $this->setStatusCode(201)->withItem($model, $transformer); }
/** * */ protected function save() { $data = $this->request->all(); $this->modelItem->getForm()->updateRequestData($data); $rules = $this->modelItem->getForm()->getValidationRules(); $this->instance->validate($data, $rules); $this->instance->fill($data); if (method_exists($this->instance, 'getRepository')) { if (method_exists($this->instance->getRepository(), 'saveFromArray')) { $this->instance->getRepository()->saveFromArray($data); } else { $this->instance->save(); } } else { $this->instance->save(); } }
/** * On save, upload files. * * @param Model $model eloquent * * @return mixed false or void */ public function saving(Model $model) { if (!($attachments = $model->attachments)) { return; } foreach ($attachments as $fieldname) { if (Request::hasFile($fieldname)) { // delete prev image $file = FileUpload::handle(Request::file($fieldname), 'uploads/' . $model->getTable()); $model->{$fieldname} = $file['filename']; if ($model->getTable() == 'files') { $model->fill($file); } } else { if ($model->{$fieldname} == 'delete') { $model->{$fieldname} = null; } else { $model->{$fieldname} = $model->getOriginal($fieldname); } } } }
/** * 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 secureFill(array $input) { $this->getFillableAttribute(); return parent::fill($input); }
/** * @param array $attributes * @return $this */ public function fill(array $attributes) { $language = array_get($attributes, 'language_id', $this->language_id); foreach ($attributes as $key => $value) { if ($this->isTranslatable($key)) { $this->translate($language)->setAttribute($key, $value); unset($attributes[$key]); } } return parent::fill($attributes); }
/** * @param array $attributes * @return Model * @throws \Exception */ public function fill(array $attributes) { // First fill the image and file attributes so they don't need to be guarded?? if ($this instanceof UploadImageInterface) { // Check if we have upload type // Save the upload type to the model and remove it from attributes. //get all uploaded files to temp if (isset($attributes['_files'])) { $this->files = $attributes['_files']; unset($attributes['_files']); } // Get single uploads. foreach (array_keys($this->getImageFields()) as $imageFieldName) { // Check for direct upload if (array_key_exists($imageFieldName, $attributes)) { if (is_object($attributes[$imageFieldName])) { $this->files['_single'][$imageFieldName] = $attributes[$imageFieldName]; unset($attributes[$imageFieldName]); } else { // We probably have image field collision! // TODO FIX THAT. } } // Check for single delete if (array_key_exists($imageFieldName . '_' . 'delete', $attributes) && $attributes[$imageFieldName . '_' . 'delete']) { // we mark it for delete $this->files['_single'][$imageFieldName]['delete'] = 1; unset($attributes[$imageFieldName . '_' . 'delete']); } } } return parent::fill($attributes); }
protected function storeArray($data) { $this->getNew($data); $this->model->fill($data); return $this->model->save(); }
/** * Update a snippet * * @param Illuminate\Database\Eloquent\Model $snippet Snippet Model * @param array $data Array of inputs * @return boolean */ public function update($snippet, array $input) { $snippet->fill($input); if ($snippet->save()) { if (isset($input['tags'])) { $snippet->tags()->sync($input['tags']); } else { $snippet->tags()->detach(); } return true; } return false; }
/** * fill * * @param array $attributes attributes * @return void */ public function fill(array $attributes) { if ($this->dynamic === true) { $this->dynamicAttributes = $attributes; $attributes = $this->filter($attributes); } return parent::fill($attributes); }
/** * @param array $input * @return $this * * @throws \Illuminate\Database\Eloquent\MassAssignmentException */ public function fill($input) { return $this->model->fill($input); }
public function fill(array $attributes) { foreach ($attributes as $key => $values) { if (is_array($values) && $this->isKeyALocale($key)) { foreach ($values as $translationAttribute => $translationValue) { if ($this->alwaysFillable() || $this->isFillable($translationAttribute)) { $this->getTranslationOrNew($key)->{$translationAttribute} = $translationValue; } } unset($attributes[$key]); } } return parent::fill($attributes); }
/** * * @param array $data * @return Model */ public function dataForCompany(array $data) { $data['company_id'] = $this->companyId; return $this->model->fill($data); }
/** * Fill the model with an array of attributes. * * @param array $attributes * * @return $this * * @throws \Illuminate\Database\Eloquent\MassAssignmentException */ public function fill(array $attributes) { if ($this->getSection()) { $this->getEditableFields()->getFields()->each(function (FieldInterface $field) use(&$attributes) { $field->onDocumentFill($this, array_get($attributes, $field->getDBKey())); unset($attributes[$field->getDBKey()]); }); } parent::fill($attributes); return $this; }
/** * @param Model $model * @param array $data */ protected function setModelData($model, array $data) { $model->fill($data); }
public function fill(array $attributes, $prepare = true) { // Make sure the entity configuration is loaded // before we attempt to fill the model. $this->prepareConfig(); // This let's us use our relationship aliases to // set relationships as they are being filled. if ($prepare) { $attributes = $this->prepareAttributes($attributes); } return parent::fill($attributes); }
/** * * @param array $data * @return Model */ public function dataForCompany(array $data) { return $this->model->fill($data); }
public function fill(array $atributos) { foreach ($atributos as $key => $atributo) { if ($atributo == '' && !$this->isBooleanField($key)) { $atributos[$key] = null; } else { if ($atributo == '' || is_null($atributo)) { $atributos[$key] = false; } else { if ($atributo != '' && $this->isDecimalField($key)) { $atributos[$key] = Helper::tf($atributo); } } } } return parent::fill($atributos); }
public function fill(array $attributes) { $this->clearEntityCacheByTableColumns(); return parent::fill($attributes); }
public function fill(array $attributes = array()) { parent::fill($attributes); $this->setTransformer(null); return $this; }