本文整理汇总了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();
}
示例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);
}
示例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;
}
示例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('*');
}
示例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;
}
示例6: getKeyName
public function getKeyName()
{
if ($this->model instanceof Model) {
return $this->model->getKeyName();
}
$model = $this->app->make($this->modelClass);
return $model->getKeyName();
}
示例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);
}
示例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);
};
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}