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


PHP Model::getKeyName方法代码示例

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


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

示例1: getJWTIdentifier

 /**
  * Get JWT identifier.
  * Defaults to the model id.
  *
  * @return string|int
  */
 public function getJWTIdentifier()
 {
     if (!method_exists($this->model, 'getJWTIdentifier')) {
         return $this->model->{$this->model->getKeyName()};
     }
     return $this->model->getJWTIdentifier();
 }
开发者ID:devdk,项目名称:signy,代码行数:13,代码来源:JWTSubject.php

示例2: findMany

 /**
  * Find a model by its primary key.
  *
  * @param  array  $id
  * @param  array  $columns
  * @return \Illuminate\Database\Eloquent\Model|Collection|static
  */
 public function findMany($id, $columns = array('*'))
 {
     if (empty($id)) {
         return new Collection();
     }
     $this->query->whereIn($this->model->getKeyName(), $id);
     return $this->get($columns);
 }
开发者ID:hilmysyarif,项目名称:l4-bootstrap-admin,代码行数:15,代码来源:Builder.php

示例3: interpolateValidationRules

 /**
  * Interpolate model attribute values on validation rules.
  *
  * @param  array $rules
  * @param  array $model
  * @return array
  */
 protected function interpolateValidationRules($rules, $model)
 {
     foreach ($rules as &$rule) {
         $attrs = last(chars_within($rule, ['{', '}']));
         foreach ($attrs as $attr) {
             $rule = str_replace('{' . $attr . '}', is_null($model[$attr]) && $attr == $this->model->getKeyName() ? 'NULL' : $model[$attr], $rule);
         }
     }
     return $rules;
 }
开发者ID:sedp-mis,项目名称:base-repository,代码行数:17,代码来源:Validation.php

示例4: filterModelAttributes

 public static function filterModelAttributes($array, Model $model)
 {
     $column = array();
     foreach ($array as $attribute => $value) {
         if (in_array($attribute, $model->getFillable())) {
             $column[] = $attribute;
         }
     }
     array_has($column, $model->getKeyName()) == false & count($column) > 0 ? $column[] = $model->getKeyName() : null;
     return count($column) > 0 ? $column : array('*');
 }
开发者ID:jamesddube,项目名称:mps-server,代码行数:11,代码来源:Api.php

示例5: fillModel

 /**
  * New From Hit Builder.
  *
  * Variation on newFromBuilder. Instead, takes
  *
  * @param $model
  * @param array $hit
  *
  * @return static
  */
 public function fillModel(Model $model, $hit = [])
 {
     $key_name = $model->getKeyName();
     $attributes = $hit['_source'];
     if (isset($hit['_id'])) {
         $attributes[$key_name] = is_numeric($hit['_id']) ? intval($hit['_id']) : $hit['_id'];
     }
     // Add fields to attributes
     if (isset($hit['fields'])) {
         foreach ($hit['fields'] as $key => $value) {
             $attributes[$key] = $value;
         }
     }
     $instance = $this->newFromBuilderRecursive($model, $attributes);
     // In addition to setting the attributes
     // from the index, we will set the score as well.
     $instance->documentScore = $hit['_score'];
     // This is now a model created
     // from an Elasticsearch document.
     $instance->isDocument = true;
     // Set our document version if it's
     if (isset($hit['_version'])) {
         $instance->documentVersion = $hit['_version'];
     }
     return $instance;
 }
开发者ID:sleimanx2,项目名称:plastic,代码行数:36,代码来源:EloquentFiller.php

示例6: getKeyName

 public function getKeyName()
 {
     if ($this->model instanceof Model) {
         return $this->model->getKeyName();
     }
     $model = $this->app->make($this->modelClass);
     return $model->getKeyName();
 }
开发者ID:sjfinder,项目名称:repository,代码行数:8,代码来源:BaseRepository.php

示例7: __construct

 /**
  * Create a new instance of relation.
  *
  * @param \Illuminate\Database\Eloquent\Builder $query
  * @param \Illuminate\Database\Eloquent\Model   $parent
  * @param array                                 $models
  * @param string|null                           $localKey
  * @param string                                $prefix
  * @param array                                 $foreignKeyLookup
  */
 public function __construct(Builder $query, Model $parent, array $models, $localKey = null, $prefix = '', $foreignKeyLookup = [])
 {
     $this->models = $models;
     $this->localKey = $localKey ?: $parent->getKeyName();
     $this->prefix = $prefix;
     $this->foreignKeyLookup = $foreignKeyLookup;
     parent::__construct($query, $parent);
 }
开发者ID:dannyweeks,项目名称:belongs-to-through,代码行数:18,代码来源:BelongsToThrough.php

示例8: getJoinClause

 /**
  * @param \Illuminate\Database\Eloquent\Model $model
  * @param string $locale
  * @param string $alias
  * @return callable
  */
 protected function getJoinClause(Eloquent $model, $locale, $alias)
 {
     return function (JoinClause $join) use($model, $locale, $alias) {
         $primary = $model->getKeyName();
         $foreign = $model->getForeignKey();
         $langKey = $model->getLocaleKey();
         $join->on($alias . '.' . $foreign, '=', $this->table . '.' . $primary)->where($alias . '.' . $langKey, '=', $locale);
     };
 }
开发者ID:laraplus,项目名称:translatable,代码行数:15,代码来源:TranslatableScope.php

示例9: resolveModelToArray

 /**
  * @param Model $oModel
  * @return array
  */
 protected function resolveModelToArray(Model $oModel)
 {
     /** @var Key $oKey */
     $oKey = $oModel->getAttribute("key");
     /** @var Locale $oLocale */
     $oLocale = $oModel->getAttribute("locale");
     $aReturn = [$oModel->getKeyName() => $oModel->getKey(), "key" => $oKey ? $oKey->getAttribute(Key::COLUMN_NAME) : null, "locale" => $oLocale ? $oLocale->getAttribute(Locale::COLUMN_CODE) : null, Message::COLUMN_TEXT => $oModel->getAttribute(Message::COLUMN_TEXT)];
     return $aReturn;
 }
开发者ID:samcrosoft,项目名称:MicroTranslate,代码行数:13,代码来源:MessageTransformer.php

示例10: count

 public function count($columns = null)
 {
     // Count rows using the model's primary key by default
     if ($columns === null) {
         $columns = $this->model->getKeyName();
     }
     // If we cannot determine the columns to match, count all columns
     if (!$columns) {
         $columns = '*';
     }
     return $this->select()->count($columns);
 }
开发者ID:monospice,项目名称:spicy-repositories,代码行数:12,代码来源:EloquentRepository.php

示例11: enviarImagem

 public function enviarImagem(Model $obj, $tipo, UploadedFile $file, $substituir = false)
 {
     //EXCLUINDO ANTIGA
     if ($substituir) {
         $imagens = $this->findWhere([$obj->getKeyName() => $obj->getKey(), 'imagem_tipo' => $tipo], ['imagem_id']);
         foreach ($imagens as $img) {
             $this->delete($img->imagem_id);
         }
     }
     $arquivo = $obj->gerarNomeHashArquivo($file);
     $file->move($obj->folderPath(), $arquivo['completo']);
     $tamanho = getimagesize($obj->folderPath() . '/' . $arquivo['completo']);
     list($largura, $altura) = getimagesize($obj->folderPath() . "/" . $arquivo['completo']);
     if ($largura < $this->model->sizes[$tipo][0] || $altura < $this->model->sizes[$tipo][1]) {
         $img = Image::make($obj->folderPath() . "/" . $arquivo['completo']);
         $img->resizeCanvas($this->model->sizes[$tipo][0], $this->model->sizes[$tipo][1], 'center');
         $img->save($obj->folderPath() . "/" . $arquivo['completo']);
         $tamanho = getimagesize($obj->folderPath() . '/' . $arquivo['completo']);
     }
     $imagem = $this->create([$obj->getKeyName() => $obj->getKey(), 'imagem_tipo' => $tipo, 'imagem_nome' => $arquivo['completo'], 'imagem_largura' => $tamanho[0], 'imagem_altura' => $tamanho[1]]);
     return $imagem;
 }
开发者ID:giordanolima,项目名称:laravel-adminlte,代码行数:22,代码来源:ImagensRepository.php

示例12: apply

 /**
  * Apply the scope to a given Eloquent query builder.
  *
  * @param  \Illuminate\Database\Eloquent\Builder $builder
  * @param  \Illuminate\Database\Eloquent\Model $model
  * @return void
  */
 public function apply(Builder $builder, Model $model)
 {
     //Check if is an override
     //
     $iso = config()->get('local_override');
     if (empty($iso)) {
         $iso = app()->getLocale();
     }
     $builder->whereExists(function ($query) use($model, $iso) {
         $query->select(\DB::raw(1))->from($model->getQualifiedTable())->whereRaw($model->getTable() . '.' . $model->getKeyName() . ' = ' . $model->getQualifiedIdElementColumn())->where($model->getQualifiedIsoColumn(), $iso)->where($model->getQualifiedModelColumn(), $model->getTable());
     });
     $this->extend($builder);
 }
开发者ID:SchizoDuckie,项目名称:Expendable,代码行数:20,代码来源:TranslatableScope.php

示例13: delete

 /**
  * {@inheritdoc}
  */
 public function delete($ids)
 {
     $ids = is_array($ids) ? $ids : func_get_args();
     if (empty($ids)) {
         return 0;
     }
     $key = $this->model->getKeyName();
     $count = 0;
     foreach ($this->newQuery()->whereIn($key, $ids)->get() as $item) {
         if ($item->delete()) {
             $count++;
         }
     }
     return $count;
 }
开发者ID:guratr,项目名称:cruddy,代码行数:18,代码来源:BaseRepository.php

示例14: updateMany

 /**
  * Update multiple models attributes in the storage.
  *
  * @param  array  $items
  * @return \Illuminate\Database\Eloquent\Collection
  */
 public function updateMany(array $items)
 {
     $ids = array_pluck($items, $this->model->getKeyName());
     $models = $this->model->find($ids);
     foreach ($models as $model) {
         $attributes = array_first($items, function ($i, $attributes) use($model) {
             if (!array_key_exists($model->getKeyName(), $attributes)) {
                 return false;
             }
             return $attributes[$model->getKeyName()] == $model->getKey();
         });
         $this->validation()->validate('update', array_merge($attributes, [$model->getKeyName() => $model->getKey()]));
         $model->fill($attributes);
         $model->save();
     }
     return $models;
 }
开发者ID:sedp-mis,项目名称:base-repository,代码行数:23,代码来源:BaseRepositoryEloquent.php

示例15: performInsert

 /**
  * Save a new model and attach it to the parent model.
  *
  * @param  \Illuminate\Database\Eloquent\Model  $model
  * @return \Illuminate\Database\Eloquent\Model
  */
 public function performInsert(Model $model)
 {
     // Generate a new key if needed.
     if ($model->getKeyName() == '_id' and !$model->getKey()) {
         $model->setAttribute('_id', new MongoId());
     }
     // For deeply nested documents, let the parent handle the changes.
     if ($this->isNested()) {
         $this->associate($model);
         return $this->parent->save();
     }
     $result = $this->getBaseQuery()->update(array($this->localKey => $model->getAttributes()));
     // Attach the model to its parent.
     if ($result) {
         $this->associate($model);
     }
     return $result ? $model : false;
 }
开发者ID:rohmad-st,项目名称:laravel-mongodb,代码行数:24,代码来源:EmbedsOne.php


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