本文整理汇总了PHP中Illuminate\Database\Eloquent\Relations\Relation类的典型用法代码示例。如果您正苦于以下问题:PHP Relation类的具体用法?PHP Relation怎么用?PHP Relation使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Relation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: boot
/**
* Boot the application events.
*
* @return void
*/
public function boot()
{
$this->registerTranslations();
$this->registerConfig();
$this->registerViews();
Relation::morphMap(['quran_recordings' => \Modules\Quran\Entities\QuranRecording::class]);
}
示例2: boot
/**
* Boot the application events.
*
* @return void
*/
public function boot(Router $router)
{
$router->model('uuser', '\\Modules\\Users\\Entities\\User');
$router->model('urole', '\\Bican\\Roles\\Models\\Role');
$this->registerTranslations();
$this->registerConfig();
$this->registerViews();
Relation::morphMap(['users' => \Modules\Users\Entities\User::class]);
}
示例3: addHasWhere
/**
* Add the "has" condition where clause to the query.
*
* @param \Illuminate\Database\Eloquent\Builder $hasQuery
* @param \Illuminate\Database\Eloquent\Relations\Relation $relation
* @param string $operator
* @param int $count
* @param string $boolean
* @return \Illuminate\Database\Eloquent\Builder
*/
protected function addHasWhere(EloquentBuilder $hasQuery, Relation $relation, $operator, $count, $boolean)
{
$query = $hasQuery->getQuery();
// Get the number of related objects for each possible parent.
$relationCount = array_count_values($query->lists($relation->getHasCompareKey()));
// Remove unwanted related objects based on the operator and count.
$relationCount = array_filter($relationCount, function ($counted) use($count, $operator) {
// If we are comparing to 0, we always need all results.
if ($count == 0) {
return true;
}
switch ($operator) {
case '>=':
case '<':
return $counted >= $count;
case '>':
case '<=':
return $counted > $count;
case '=':
case '!=':
return $counted == $count;
}
});
// If the operator is <, <= or !=, we will use whereNotIn.
$not = in_array($operator, array('<', '<=', '!='));
// If we are comparing to 0, we need an additional $not flip.
if ($count == 0) {
$not = !$not;
}
// All related ids.
$relatedIds = array_keys($relationCount);
// Add whereIn to the query.
return $this->whereIn($this->model->getKeyName(), $relatedIds, $boolean, $not);
}
示例4: verifyRelation
protected function verifyRelation(ReflectionMethod $method, Relation $relationship)
{
$expectedRelatedModel = $this->relatedModel === get_class($relationship->getRelated());
$expectedRelationName = get_class($relationship) === $this->type;
$expectedReturnAnnotation = $this->getReturnAnnotation($method) === $this->type;
return $expectedRelationName && $expectedRelatedModel && $expectedReturnAnnotation;
}
示例5: deleteAllRelatedExcept
/**
* @param Relation $relation
* @param array $excluded_ids
*/
public static function deleteAllRelatedExcept(Relation $relation, $excluded_ids = [])
{
$related = $relation->getRelated();
$key_name = $related->getKeyName();
$query = $relation->getQuery();
if (count($excluded_ids) > 0) {
$query->whereNotIn($key_name, $excluded_ids);
}
$query->delete();
}
示例6: addJoinToQuery
/**
* @param $joinTableAlias
* @param $currentTableAlias
* @param BelongsTo|Relation $relation
* @param string $columnsPrefix
*/
protected function addJoinToQuery($joinTableAlias, $currentTableAlias, Relation $relation, $columnsPrefix = '')
{
$joinTableName = $relation->getRelated()->getTable();
$joinTable = implode(' as ', [$joinTableName, $joinTableAlias]);
$joinLeftCondition = implode('.', [$joinTableAlias, $relation->getOtherKey()]);
$joinRightCondition = implode('.', [$currentTableAlias, $relation->getForeignKey()]);
$this->query->leftJoin($joinTable, $joinLeftCondition, '=', $joinRightCondition);
$columns = $this->getColumns($joinTableName);
$prefix = static::$prefix . $columnsPrefix . $joinTableAlias . '---';
foreach ($columns as $column) {
$this->selectFromQuery($joinTableAlias, $column, $prefix . $column);
}
}
示例7: __construct
public function __construct(array $config, ModelManager $modelManager, Model $model, EloquentRelation $eloquentRelation, FieldFactory $fieldFactory)
{
$this->checkNameConfig($config);
$this->name = $config['name'];
$this->slug = $config['name'];
$this->relatedModel = $model;
$this->eloquentRelation = $eloquentRelation;
$this->fieldFactory = $fieldFactory;
$this->modelManager = $modelManager;
$this->config = $config;
$this->setup();
$this->modelAbstractor = \App::make('Anavel\\Crud\\Contracts\\Abstractor\\ModelFactory')->getByClassName(get_class($this->eloquentRelation->getRelated()), $this->config);
}
示例8: __construct
/**
* DescendantsRelation constructor.
*
* @param QueryBuilder $builder
* @param Model $model
*/
public function __construct(QueryBuilder $builder, Model $model)
{
if (!NestedSet::isNode($model)) {
throw new InvalidArgumentException('Model must be node.');
}
parent::__construct($builder, $model);
}
示例9: boot
/**
* Boot the application events.
*
* @return void
*/
public function boot()
{
$this->registerTranslations();
$this->registerConfig();
$this->registerViews();
Relation::morphMap(['paper_doc' => \Modules\Papers\Entities\PaperDoc::class, 'paper_semster_doc' => \Modules\Papers\Entities\PaperSemesterDoc::class]);
}
示例10: boot
/**
* Boot the application events.
*
* @return void
*/
public function boot()
{
$this->registerTranslations();
$this->registerConfig();
$this->registerViews();
Relation::morphMap(['order_quran_excuses' => \Modules\Orders\Entities\OrderQuranExcuse::class]);
}
示例11: getRelationCountQuery
/**
* Add the constraints for a relationship count query.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param \Illuminate\Database\Eloquent\Builder $parent
* @return \Illuminate\Database\Eloquent\Builder
*/
public function getRelationCountQuery(Builder $query, Builder $parent)
{
if ($parent->getQuery()->from == $query->getQuery()->from) {
return $this->getRelationCountQueryForSelfRelation($query, $parent);
}
return parent::getRelationCountQuery($query, $parent);
}
示例12: boot
/**
* Boot the application events.
*
* @return void
*/
public function boot()
{
$this->registerTranslations();
$this->registerConfig();
$this->registerViews();
Relation::morphMap(['teachers' => \Modules\Teachers\Entities\Teacher::class]);
}
示例13: getRelationQuery
/**
* Add the constraints for a relationship query.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param \Illuminate\Database\Eloquent\Builder $parent
* @param array|mixed $columns
* @return \Illuminate\Database\Eloquent\Builder
*/
public function getRelationQuery(Builder $query, Builder $parent, $columns = ['*'])
{
if ($parent->getQuery()->from == $query->getQuery()->from) {
return $this->getRelationQueryForSelfRelation($query, $parent, $columns);
}
return parent::getRelationQuery($query, $parent, $columns);
}
示例14: boot
/**
* Boot the application events.
*
* @return void
*/
public function boot()
{
$this->registerTranslations();
$this->registerConfig();
$this->registerViews();
Relation::morphMap([]);
}
示例15: __construct
/**
* Create a new has many relationship instance.
*
* @param Illuminate\Database\Eloquent\Builder $query
* @param Illuminate\Database\Eloquent\Model $parent
* @param string $table
* @param string $foreignKey
* @param string $otherKey
* @return void
*/
public function __construct(Builder $query, Model $parent, $table, $foreignKey, $otherKey)
{
$this->table = $table;
$this->otherKey = $otherKey;
$this->foreignKey = $foreignKey;
parent::__construct($query, $parent);
}