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


PHP Model::getKey方法代码示例

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


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

示例1: addTenant

 /**
  * Add a tenant to scope by.
  *
  * @param string|Model $tenant
  * @param mixed|null   $id
  */
 public function addTenant($tenant, $id = null)
 {
     if (func_num_args() == 1) {
         $id = $tenant->getKey();
     }
     $this->tenants->put($this->getTenantKey($tenant), $id);
 }
开发者ID:HipsterJazzbo,项目名称:Landlord,代码行数:13,代码来源:TenantManager.php

示例2: 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;
 }
开发者ID:cocona,项目名称:core,代码行数:12,代码来源:EloquentResource.php

示例3: addConstraints

 /**
  * Set the base constraints on the relation query.
  *
  * @return void
  */
 public function addConstraints()
 {
     $parentTable = $this->parent->getTable();
     $this->setJoin();
     if (static::$constraints) {
         $this->query->where($parentTable . '.' . $this->firstKey, '=', $this->farParent->getKey());
     }
 }
开发者ID:mawaha,项目名称:tracker,代码行数:13,代码来源:HasManyThrough.php

示例4: save

 /**
  * Save the resource in storage.
  *
  * @param  string
  * @return Response
  */
 protected function save($action)
 {
     // Set feedback message depending on action type
     switch ($action) {
         default:
             $successMessage = _('%s successfully saved');
             $errorMessage = _('Unable to save %s');
             break;
         case 'store':
         case '_store':
             $successMessage = _('%s successfully created');
             $errorMessage = _('Unable to create %s');
             break;
         case 'update':
         case '_update':
             $successMessage = _('%s successfully updated');
             $errorMessage = _('Unable to update %s');
             break;
     }
     // Persist to storage
     try {
         if (!$this->resource->save()) {
             throw new DomainException($errorMessage);
         }
         Session::flash('success', sprintf($successMessage, $this->resource));
         return redirect()->route($this->route . '.show', [$this->resource->getKey()]);
     } catch (DomainException $e) {
         Session::flash('error', sprintf($e->getMessage(), $this->resource));
         return redirect()->back()->withInput();
     }
 }
开发者ID:LeandrosilvaDG,项目名称:Wiki,代码行数:37,代码来源:ResourceController.php

示例5: remove

 /**
  * Removes a model from this relationship type.
  */
 public function remove(Model $model, $sessionKey = null)
 {
     if ($sessionKey === null) {
         $this->detach($model->getKey());
     } else {
         $this->parent->unbindDeferred($this->relationName, $model, $sessionKey);
     }
 }
开发者ID:nevinsm,项目名称:personalSite,代码行数:11,代码来源:BelongsToMany.php

示例6: encode

 /**
  * @param Model $user
  *
  * @return string
  */
 public function encode(Model $user)
 {
     /** @var User $user */
     $secret = str_random();
     $token = json_encode([self::KEY_USER_ID => $user->getKey(), self::KEY_SECRET => $secret]);
     $user->{User::FIELD_API_TOKEN} = $secret;
     $user->saveOrFail();
     return $token;
 }
开发者ID:InactiveProjects,项目名称:limoncello-illuminate,代码行数:14,代码来源:TokenCodec.php

示例7: 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

示例8: delete

 /**
  * Delete a model document.
  *
  * @return mixed
  */
 public function delete()
 {
     $this->exitIfModelNotSet();
     $params = ['id' => $this->model->getKey(), 'type' => $this->model->getDocumentType(), 'index' => $this->model->getDocumentIndex()];
     // check if the document exists before deleting
     if ($this->connection->existsStatement($params)) {
         return $this->connection->deleteStatement($params);
     }
     return true;
 }
开发者ID:sleimanx2,项目名称:plastic,代码行数:15,代码来源:EloquentPersistence.php

示例9: associate

 public function associate($key, Model $model)
 {
     /** @var Collection $collection */
     $collection = $this->relation->getParent()->{$key};
     foreach ($collection as $position => $m) {
         // already in there
         if ($model === $m) {
             return;
         }
         if ($model->getKey() && $model->getKey() == $m->getKey()) {
             // found a different instance with the same key, substitute it
             $collection[$position] = $model;
             return;
         }
     }
     // if it get's to here, there's no matching model, so we just append the
     // new one at the end of the collection
     $collection[] = $model;
 }
开发者ID:tacone,项目名称:datasource,代码行数:19,代码来源:HasManyWrapper.php

示例10: block_btn_show

 /**
  * 生成查看详情按钮 GET方式跳转新页面
  * @param CrudController $controller
  * @param Model $item
  * @return string
  */
 public static function block_btn_show(CrudController $controller, Model $item)
 {
     $url = $controller->redirectToMethodUrl('getShow', $controller, [$item->getKey()]);
     $action = 'admin::' . $controller::getActionPrefix() . '.show.detail';
     if (AdminAuthMiddleware::canAccess($action, \Auth::user())) {
         $disabled = '';
     } else {
         $disabled = 'disabled';
     }
     return "<a class='btn btn-sm btn-info gofarms-btn-actions' href='{$url}' target='_blank' {$disabled}><span class='glyphicon glyphicon-search'></span></a>";
 }
开发者ID:xjtuwangke,项目名称:laravel-bundles,代码行数:17,代码来源:ButtonUtils.php

示例11: getQueries

 /**
  * Get all of the queries that would be run for a migration.
  *
  * @param  object  $migration
  * @param  string  $method
  *
  * @return array
  */
 protected function getQueries($migration, $method)
 {
     $connection = $migration->getConnection();
     // Now that we have the connections we can resolve it and pretend to run the
     // queries against the database returning the array of raw SQL statements
     // that would get fired against the database system for this migration.
     $db = $this->resolveConnection($connection);
     return $db->pretend(function () use($migration, $method) {
         call_user_func([$migration, $method], $this->entity->getKey(), $this->entity);
     });
 }
开发者ID:DavidIWilson,项目名称:site1,代码行数:19,代码来源:Migrator.php

示例12: scopeForModel

 /**
  * Constrain a query to an ability for a specific model.
  *
  * @param  \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder  $query
  * @param  \Illuminate\Database\Eloquent\Model  $model
  * @return void
  */
 public function scopeForModel($query, Model $model)
 {
     $query->where(function ($query) use($model) {
         $query->where('entity_type', $model->getMorphClass());
         $query->where(function ($query) use($model) {
             $query->whereNull('entity_id');
             if ($model->exists) {
                 $query->orWhere('entity_id', $model->getKey());
             }
         });
     });
 }
开发者ID:Gummibeer,项目名称:bouncer,代码行数:19,代码来源:Ability.php

示例13: 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

示例14: abilitySubqueryConstraint

 /**
  * Get the constraint for the ability subquery.
  *
  * @param  \Illuminate\Database\Eloquent\Model  $model
  * @param  bool  $strict
  * @return \Closure
  */
 protected function abilitySubqueryConstraint(Model $model, $strict)
 {
     return function ($query) use($model, $strict) {
         // If the model does not exist, we want to search for blanket abilities
         // that cover all instances of this model. If it does exist, we only
         // want to find blanket abilities if we're not using strict mode.
         if (!$model->exists || !$strict) {
             $query->whereNull($this->table . '.entity_id');
         }
         if ($model->exists) {
             $query->orWhere($this->table . '.entity_id', $model->getKey());
         }
     };
 }
开发者ID:JosephSilber,项目名称:bouncer,代码行数:21,代码来源:AbilitiesForModel.php

示例15: extractModelAndKeys

 /**
  * Extract the model instance and model keys from the given parameters.
  *
  * @param  string|\Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection  $model
  * @param  array|null  $keys
  * @return array
  */
 public static function extractModelAndKeys($model, array $keys = null)
 {
     if (is_null($keys)) {
         if ($model instanceof Model) {
             return [$model, [$model->getKey()]];
         }
         if ($model instanceof Collection) {
             return [$model->first(), $model->modelKeys()];
         }
     } else {
         if (is_string($model)) {
             $model = new $model();
         }
         return [$model, $keys];
     }
 }
开发者ID:JosephSilber,项目名称:bouncer,代码行数:23,代码来源:Helper.php


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