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


PHP Model::getMorphClass方法代码示例

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


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

示例1: createAssignRecords

 /**
  * Create the pivot table records for assigning the role to given models.
  *
  * @param  \Illuminate\Database\Eloquent\Model  $model
  * @param  array  $keys
  * @return array
  */
 protected function createAssignRecords(Model $model, array $keys)
 {
     $type = $model->getMorphClass();
     return array_map(function ($key) use($type) {
         return ['role_id' => $this->getKey(), 'entity_type' => $type, 'entity_id' => $key];
     }, $keys);
 }
开发者ID:JosephSilber,项目名称:bouncer,代码行数:14,代码来源:IsRole.php

示例2: __construct

 /**
  * Create a new morph to many relationship instance.
  *
  * @param  \Illuminate\Database\Eloquent\Builder  $query
  * @param  \Illuminate\Database\Eloquent\Model  $parent
  * @param  string  $name
  * @param  string  $table
  * @param  string  $foreignKey
  * @param  string  $otherKey
  * @param  string  $relationName
  * @param  bool  $inverse
  * @return void
  */
 public function __construct(Builder $query, Model $parent, $name, $table, $foreignKey, $otherKey, $relationName = null, $inverse = false)
 {
     $this->inverse = $inverse;
     $this->morphType = $name . '_type';
     $this->morphClass = $inverse ? $query->getModel()->getMorphClass() : $parent->getMorphClass();
     parent::__construct($query, $parent, $table, $foreignKey, $otherKey, $relationName);
 }
开发者ID:manhvu1212,项目名称:videoplatform,代码行数:20,代码来源:MorphToMany.php

示例3: constrainByModel

 /**
  * 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
  * @param  bool  $strict
  * @return void
  */
 protected function constrainByModel($query, Model $model, $strict = false)
 {
     $query->where(function ($query) use($model, $strict) {
         $query->where($this->table . '.entity_type', $model->getMorphClass());
         $query->where($this->abilitySubqueryConstraint($model, $strict));
     });
 }
开发者ID:JosephSilber,项目名称:bouncer,代码行数:15,代码来源:AbilitiesForModel.php

示例4: getCurrentPoints

 /**
  * @param Model $pointable
  *
  * @return static
  */
 public function getCurrentPoints(Model $pointable)
 {
     $currentPoint = Transaction::where('pointable_id', $pointable->id)->where('pointable_type', $pointable->getMorphClass())->orderBy('created_at', 'desc')->lists('current')->first();
     if (!$currentPoint) {
         $currentPoint = 0.0;
     }
     return $currentPoint;
 }
开发者ID:Trexology,项目名称:laravel-pointable,代码行数:13,代码来源:Transaction.php

示例5: hasRolesIn

 /**
  * @param String $roles
  * @param Model $model
  * @return bool
  * @throws IsNotStringException
  */
 public function hasRolesIn($roles, Model $model)
 {
     if (is_string($roles)) {
         $perm = $this->newPermission();
         $permissions = $perm->where('permable_type', $model->getMorphClass())->where('permable_id', $model->id)->where('user_id', $this->id)->whereHas('roles', function ($query) use($roles) {
             $query->where('name', $roles);
         })->first();
         return !is_null($permissions);
     }
     throw new IsNotStringException('Parameter 1 must be a string.');
 }
开发者ID:ArnaudTarroux,项目名称:Laravel-roles,代码行数:17,代码来源:HasRoleTrait.php

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

示例7: associate

 /**
  * Associate the model instance to the given parent.
  *
  * @param  \Illuminate\Database\Eloquent\Model  $model
  * @return \Illuminate\Database\Eloquent\Model
  */
 public function associate(Model $model)
 {
     $this->parent->setAttribute($this->foreignKey, $model->getKey());
     $this->parent->setAttribute($this->morphType, $model->getMorphClass());
     return $this->parent->setRelation($this->relation, $model);
 }
开发者ID:hilmysyarif,项目名称:phpv8,代码行数:12,代码来源:MorphTo.php

示例8: joinSegment

 /**
  * Join relation's table accordingly.
  *
  * @param  \Sofa\Eloquence\Builder $query
  * @param  string $segment
  * @param  \Illuminate\Database\Eloquent\Model $parent
  * @return array
  */
 protected function joinSegment(Builder $query, $segment, EloquentModel $parent)
 {
     $relation = $parent->{$segment}();
     $related = $relation->getRelated();
     $table = $related->getTable();
     // If the table has been already joined let's skip it. Otherwise we will left join
     // it in order to allow using some query methods on mapped columns. Polymorphic
     // relations require also additional constraints, so let's handle it as well.
     if (!$this->alreadyJoined($query, $table)) {
         list($fk, $pk) = $this->getJoinKeys($relation);
         $query->leftJoin($table, function ($join) use($fk, $pk, $relation, $parent, $related) {
             $join->on($fk, '=', $pk);
             if ($relation instanceof MorphOne || $relation instanceof MorphTo) {
                 $morphClass = $relation instanceof MorphOne ? $parent->getMorphClass() : $related->getMorphClass();
                 $join->where($relation->getMorphType(), '=', $morphClass);
             }
         });
     }
     return [$table, $related];
 }
开发者ID:rafwlaz,项目名称:eloquence,代码行数:28,代码来源:Mappable.php

示例9: __construct

 /**
  * Create a new morph one or many relationship instance.
  *
  * @param  \Illuminate\Database\Eloquent\Builder $query
  * @param  \Illuminate\Database\Eloquent\Model $parent
  * @param  string $type
  * @param  string $id
  * @param  string $localKey
  * @return void
  */
 public function __construct(Builder $query, Model $parent, $type, $id, $localKey)
 {
     $this->morphType = $type;
     $this->morphClass = $parent->getMorphClass();
     parent::__construct($query, $parent, $id, $localKey);
 }
开发者ID:scrobot,项目名称:Lumen,代码行数:16,代码来源:MorphOneOrMany.php

示例10: createForModel

 /**
  * Create a new permission for a specific model.
  *
  * @param  \Illuminate\Database\Eloquent\Model  $model
  * @param  string  $name
  * @return static
  */
 public static function createForModel(Model $model, $name)
 {
     return static::forceCreate(['name' => $name, 'entity_type' => $model->getMorphClass(), 'entity_id' => $model->exists ? $model->getKey() : null]);
 }
开发者ID:devonzara,项目名称:bouncer,代码行数:11,代码来源:Permission.php

示例11: getJoinClause

 /**
  * Get the join clause for related table.
  *
  * @param  \Illuminate\Database\Eloquent\Model $parent
  * @param  \Illuminate\Database\Eloquent\Relations\Relation $relation
  * @param  string $type
  * @param  string $table
  * @return \Illuminate\Database\Query\JoinClause
  */
 protected function getJoinClause(Model $parent, Relation $relation, $table, $type)
 {
     list($fk, $pk) = $this->getJoinKeys($relation);
     $join = (new Join($type, $table))->on($fk, '=', $pk);
     if ($relation instanceof MorphOneOrMany) {
         $join->where($relation->getMorphType(), '=', $parent->getMorphClass());
     }
     return $join;
 }
开发者ID:boukeversteegh,项目名称:eloquence,代码行数:18,代码来源:Joiner.php

示例12: addComment

 /**
  *  Add comment ..
  *
  * @param $comment
  * @param Model $author
  * @param string $status
  */
 public function addComment($comment, Model $author, $status = 'pending')
 {
     $commentRow = new Comment(['author_id' => $author->id, 'author_type' => $author->getMorphClass(), 'comment' => $comment, 'status' => $status]);
     return $this->comments()->save($commentRow);
 }
开发者ID:parfumix,项目名称:eloquent-commentable,代码行数:12,代码来源:CommentTrait.php

示例13: getCacheKey

 /**
  * Get the cache key for the given model's cache type.
  *
  * @param  \Illuminate\Database\Eloquent\Model  $model
  * @param  string  $type
  * @param  bool  $allowed
  * @return string
  */
 protected function getCacheKey(Model $model, $type, $allowed = true)
 {
     return implode('-', [$this->tag, $type, $model->getMorphClass(), $model->getKey(), $allowed ? 'a' : 'f']);
 }
开发者ID:JosephSilber,项目名称:bouncer,代码行数:12,代码来源:CachedClipboard.php

示例14: makeElasticSearchOneExpectation

 /**
  * Makes a Mockery expectation for one item.
  *
  * @return \Mockery\Matcher\Closure
  */
 protected function makeElasticSearchOneExpectation(Model $model)
 {
     return \Mockery::on(function (Model $entity) use($model) {
         return get_class($entity) == $model->getMorphClass() && $entity->getKey() == $model->getKey();
     });
 }
开发者ID:spira,项目名称:api-core,代码行数:11,代码来源:ElasticSearchIndexerTrait.php

示例15: scopeWhereGroup

 /**
  * @param $query
  * @param Model $model
  * @param string $groupSlug
  * @return \Illuminate\Database\Eloquent\Builder
  */
 public function scopeWhereGroup($query, $model, $groupSlug)
 {
     $groupsPivotTable = config('friendships.tables.fr_groups_pivot');
     $friendsPivotTable = config('friendships.tables.fr_pivot');
     $groupsAvailable = config('friendships.groups', []);
     if ('' !== $groupSlug && isset($groupsAvailable[$groupSlug])) {
         $groupId = $groupsAvailable[$groupSlug];
         $query->join($groupsPivotTable, function ($join) use($groupsPivotTable, $friendsPivotTable, $groupId, $model) {
             $join->on($groupsPivotTable . '.friendship_id', '=', $friendsPivotTable . '.id')->where($groupsPivotTable . '.group_id', '=', $groupId)->where(function ($query) use($groupsPivotTable, $friendsPivotTable, $model) {
                 $query->where($groupsPivotTable . '.friend_id', '!=', $model->getKey())->where($groupsPivotTable . '.friend_type', '=', $model->getMorphClass());
             })->orWhere($groupsPivotTable . '.friend_type', '!=', $model->getMorphClass());
         });
     }
     return $query;
 }
开发者ID:hootlex,项目名称:laravel-friendships,代码行数:21,代码来源:Friendship.php


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