当前位置: 首页>>代码示例>>PHP>>正文


PHP Model::newInstance方法代码示例

本文整理汇总了PHP中Illuminate\Database\Eloquent\Model::newInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP Model::newInstance方法的具体用法?PHP Model::newInstance怎么用?PHP Model::newInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Illuminate\Database\Eloquent\Model的用法示例。


在下文中一共展示了Model::newInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: create

 /**
  * Create and return a new Photo model.
  *
  * @param array $attributes
  *
  * @return \App\Photo
  */
 public function create(array $attributes)
 {
     $model = $this->model->newInstance();
     $model->fill($attributes);
     $model->save();
     return $model;
 }
开发者ID:bexarcreative,项目名称:using-rate-limiting-on-method-calls-with-laravel,代码行数:14,代码来源:PhotoRepository.php

示例2: create

 /**
  * Create a new translation record and return the model.
  *
  * @param $language
  * @param $resource
  * @param $foreignId
  * @param $field
  * @param $value
  * @return Translation
  */
 public function create($language, $resource, $foreignId, $field, $value)
 {
     $model = $this->model->newInstance();
     $model->language = $language;
     $model->foreign_id = $foreignId;
     $model->resource = $resource;
     $model->field = $field;
     $model->value = $value;
     $model->save();
     return $model;
 }
开发者ID:tectonic,项目名称:laravel-localisation,代码行数:21,代码来源:EloquentTranslationRepository.php

示例3: import

 /**
  * Import an Eloquent
  *
  * @param Model $model
  * @param array $relations
  * @param int $batchSize
  * @param callable $callback
  * @internal param $type
  */
 public function import(Model $model, $relations = [], $batchSize = 750, callable $callback = null)
 {
     $batch = 0;
     $asQueryLoggind = $model->getConnection()->logging();
     $model->getConnection()->disableQueryLog();
     while (true) {
         // Increase the batch number
         $batch += 1;
         // Load records from the database
         $records = $model->newInstance()->with($relations)->skip($batchSize * ($batch - 1))->take($batchSize)->get();
         // Break out of the loop if we are out of records
         if (count($records) == 0) {
             break;
         }
         // Call the callback function to provide feedback on the import process
         if ($callback) {
             $callback($batch);
         }
         // Transform each record before sending it to Elasticsearch
         $data = [];
         foreach ($records as $record) {
             $data[] = ['index' => ['_id' => $record->getEsId()]];
             $data[] = $record->transform(!empty($relations));
         }
         // Bulk import the data to Elasticsearch
         $this->bulk($data);
     }
     if ($asQueryLoggind) {
         $model->getConnection()->enableQueryLog();
     }
 }
开发者ID:menthol,项目名称:Flexible,代码行数:40,代码来源:Index.php

示例4: create

 /**
  * Save a new entity in repository.
  *
  * @param array $attributes
  *
  * @return mixed
  */
 public function create(array $attributes)
 {
     $model = $this->model->newInstance($attributes);
     $model->save();
     $this->resetModel();
     event(new RepositoryEntityCreated($this, $model));
     return $this->parserResult($model);
 }
开发者ID:LavaLite,项目名称:framework,代码行数:15,代码来源:BaseRepository.php

示例5: refresh

 /**
  *
  */
 protected function refresh()
 {
     if (!$this->model instanceof EloquentModel) {
         $this->model = $this->model->getModel();
     }
     $this->model = $this->model->newInstance();
     $this->criteria = new Collection();
 }
开发者ID:ablunier,项目名称:laravel-database,代码行数:11,代码来源:Repository.php

示例6: firstOrCreate

 /**
  * Get the first record matching the attributes or create it.
  *
  * @param  array  $attributes
  * @param  array  $values
  * @return \Illuminate\Database\Eloquent\Model
  */
 public function firstOrCreate(array $attributes, array $values = [])
 {
     if (!is_null($instance = $this->where($attributes)->first())) {
         return $instance;
     }
     $instance = $this->model->newInstance($attributes + $values)->setConnection($this->query->getConnection()->getName());
     $instance->save();
     return $instance;
 }
开发者ID:illuminate,项目名称:database,代码行数:16,代码来源:Builder.php

示例7: firstOrCreate

 /**
  * Get the first record matching the attributes or create it.
  *
  * @param  array  $attributes
  * @return \Illuminate\Database\Eloquent\Model
  */
 public function firstOrCreate(array $attributes)
 {
     if (!is_null($instance = $this->where($attributes)->first())) {
         return $instance;
     }
     $instance = $this->model->newInstance($attributes);
     $instance->save();
     return $instance;
 }
开发者ID:drickferreira,项目名称:rastreador,代码行数:15,代码来源:Builder.php

示例8: create

 /**
  * Save a new entity in modal.
  *
  * @param array $attributes
  *
  * @throws ValidatorException
  *
  * @return mixed
  */
 public function create(array $attributes)
 {
     $model = $this->model->newInstance();
     $attributes['user_id'] = User::users('id');
     $model->fill($attributes);
     $model->save();
     $this->resetModel();
     return $model;
 }
开发者ID:LavaliteCms,项目名称:Example,代码行数:18,代码来源:BaseRepository.php

示例9: set

 /**
  * {@inheritdoc}
  */
 public function set($keys, $value = null)
 {
     if (is_array($keys)) {
         // If we've been given an array, we'll assume they're a
         // key value pair and create a setting for each.
         array_walk($keys, function ($value, $key) {
             $this->set($key, $value);
         });
     } else {
         // We'll try to locate the setting before creating a new instance.
         $model = $this->find($keys) ?: $this->model->newInstance();
         $model->key = $keys;
         $model->value = $value;
         $model->save();
         $this->cache($keys, function () use($model) {
             return $model;
         }, $forget = true);
     }
 }
开发者ID:larapacks,项目名称:setting,代码行数:22,代码来源:Setting.php

示例10: firstOrCreate

 /**
  * Get the first record matching the attributes or create it.
  *
  * @param  array  $attributes
  * @param  array  $values
  * @return \Illuminate\Database\Eloquent\Model
  */
 public function firstOrCreate(array $attributes, array $values = [])
 {
     $mutatedAttributes = $this->model->newInstance()->forceFill($attributes)->getAttributes();
     if (!is_null($instance = $this->where($mutatedAttributes)->first())) {
         return $instance;
     }
     $instance = $this->model->newInstance($attributes + $values);
     $instance->save();
     return $instance;
 }
开发者ID:arcdigital,项目名称:framework,代码行数:17,代码来源:Builder.php

示例11: create

 /**
  * Save a new entity in repository
  *
  * @param array $attributes
  * @return mixed|Model
  */
 public function create(array $attributes)
 {
     return $this->wrap(function ($attributes) {
         $model = $this->model->newInstance($attributes);
         /**
          * @var Model $model
          */
         $model->save();
         return $model;
     }, new Action(__METHOD__, func_get_args(), Action::CREATE));
 }
开发者ID:sandeeprajoria,项目名称:Housekeeper,代码行数:17,代码来源:BaseRepository.php

示例12: create

 /**
  * Save a new entity in repository
  *
  * @throws ValidatorException
  * @param array $attributes
  * @return mixed
  */
 public function create(array $attributes)
 {
     if (!is_null($this->validator)) {
         $this->validator->with($attributes)->passesOrFail(ValidatorInterface::RULE_CREATE);
     }
     $model = $this->model->newInstance($attributes);
     $model->save();
     $this->resetModel();
     event(new RepositoryEntityCreated($this, $model));
     return $this->parserResult($model);
 }
开发者ID:torosegon,项目名称:l5-repository,代码行数:18,代码来源:BaseRepository.php

示例13: assertModelPatched

 /**
  * Assert that a model has been patched.
  *
  * @param Model $model
  *      the model before it was patched.
  * @param array $changedAttributes
  *      the expected changed attributes - key to value pairs.
  * @param string|string[] $unchangedKeys
  *      the keys of the attributes that should not have changed.
  * @return $this
  */
 protected function assertModelPatched(Model $model, array $changedAttributes, $unchangedKeys = [])
 {
     /** We need to ensure values are cast to database values */
     $expected = $model->newInstance($changedAttributes)->getAttributes();
     $attributes = $model->getAttributes();
     foreach ((array) $unchangedKeys as $attr) {
         $expected[$attr] = isset($attributes[$attr]) ? $attributes[$attr] : null;
     }
     $expected[$model->getKeyName()] = $model->getKey();
     return $this->seeModelInDatabase($model, $expected);
 }
开发者ID:cloudcreativity,项目名称:laravel-json-api,代码行数:22,代码来源:InteractsWithModels.php

示例14: create

 public function create(array $attributes)
 {
     $validator = $this->validate($attributes);
     if ($validator->fails()) {
         throw ValidationError::fromValidator($validator);
     }
     $related = $this->fetchRelatedAttributes($attributes);
     $attributes = $this->transformAttributes($attributes);
     $model = $this->model->newInstance($attributes);
     $this->saveModel($model, $related);
     $this->resetModel();
     return $this->parseResult($model);
 }
开发者ID:mayconbordin,项目名称:reloquent,代码行数:13,代码来源:BaseRepository.php

示例15: newFromBuilderRecursive

 /**
  * Fill a model with form an elastic hit.
  *
  * @param Model    $model
  * @param array    $attributes
  * @param Relation $parentRelation
  *
  * @return mixed
  */
 public function newFromBuilderRecursive(Model $model, array $attributes = [], Relation $parentRelation = null)
 {
     $instance = $model->newInstance([], $exists = true);
     // fill the instance attributes with checking
     $instance->unguard();
     $instance->fill($attributes);
     $instance->reguard();
     // Load relations recursive
     $this->loadRelationsAttributesRecursive($instance);
     // Load pivot
     $this->loadPivotAttribute($instance, $parentRelation);
     return $instance;
 }
开发者ID:sleimanx2,项目名称:plastic,代码行数:22,代码来源:EloquentFiller.php


注:本文中的Illuminate\Database\Eloquent\Model::newInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。