本文整理汇总了PHP中Illuminate\Database\Eloquent\Model::fill方法的典型用法代码示例。如果您正苦于以下问题:PHP Model::fill方法的具体用法?PHP Model::fill怎么用?PHP Model::fill使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Eloquent\Model
的用法示例。
在下文中一共展示了Model::fill方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: insert
/**
* @param array $data
* @return bool
*/
public function insert(array $data = [])
{
$this->source->fill($data);
if ($this->source->save()) {
return $this->source->getKey();
}
return false;
}
示例2: dataForCompany
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);
}
示例3: fill
/**
* 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);
}
示例4: save
/**
*
*/
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();
}
示例5: toModel
/**
* {@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;
}
示例6: fill
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;
}
示例7: _update
/**
* 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__);
}
示例8: saveModelData
/**
* 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;
}
示例9: fillModel
/**
* 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;
}
示例10: withNewItem
/**
* @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);
}
示例11: save
/**
*
*/
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();
}
}
示例12: saving
/**
* 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);
}
}
}
}
示例13: fillAndSave
/**
* 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;
}
示例14: secureFill
public function secureFill(array $input)
{
$this->getFillableAttribute();
return parent::fill($input);
}
示例15: fill
/**
* @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);
}