本文整理汇总了PHP中Illuminate\Database\Eloquent\Relations\Relation类的典型用法代码示例。如果您正苦于以下问题:PHP Relation类的具体用法?PHP Relation怎么用?PHP Relation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Relation类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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]);
}
开发者ID:hisambahaa,项目名称:DARES,代码行数:12,代码来源:QuranServiceProvider.php
示例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]);
}
开发者ID:hisambahaa,项目名称:DARES,代码行数:14,代码来源:UsersServiceProvider.php
示例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);
}
开发者ID:reverserob,项目名称:laravel-mongodb,代码行数:44,代码来源:Builder.php
示例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;
}
开发者ID:fs-ap,项目名称:laravel-relationship-test,代码行数:7,代码来源:Relationship.php
示例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();
}
开发者ID:exolnet,项目名称:laravel-module,代码行数:14,代码来源:Helper.php
示例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);
}
}
开发者ID:leloulight,项目名称:trigglog,代码行数:19,代码来源:WithJoinEloquentBuilder.php
示例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);
}
开发者ID:ablunier,项目名称:crud,代码行数:13,代码来源:Relation.php
示例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);
}
开发者ID:nutsdo,项目名称:nong-store,代码行数:13,代码来源:DescendantsRelation.php
示例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]);
}
开发者ID:hisambahaa,项目名称:DARES,代码行数:12,代码来源:PapersServiceProvider.php
示例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]);
}
开发者ID:hisambahaa,项目名称:DARES,代码行数:12,代码来源:OrdersServiceProvider.php
示例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);
}
开发者ID:nsoimaru,项目名称:Laravel51-starter,代码行数:14,代码来源:HasOneOrMany.php
示例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]);
}
开发者ID:hisambahaa,项目名称:DARES,代码行数:12,代码来源:TeachersServiceProvider.php
示例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);
}
开发者ID:bryanashley,项目名称:framework,代码行数:15,代码来源:HasOneOrMany.php
示例14: boot
/**
* Boot the application events.
*
* @return void
*/
public function boot()
{
$this->registerTranslations();
$this->registerConfig();
$this->registerViews();
Relation::morphMap([]);
}
开发者ID:hisambahaa,项目名称:DARES,代码行数:12,代码来源:ExamsServiceProvider.php
示例15: sortByTag
/**
* Sort by issues tag group
* Note: this sort will return the collection
*
* @param Eloquent\Relations\Relation $query
* @param string $tagGroup
* @param string $order
*
* @return Eloquent\Collection
*/
public function sortByTag(Eloquent\Relations\Relation $query, $tagGroup, $order = 'asc')
{
// If tag group is string prefixed with tag:
if (!is_numeric($tagGroup)) {
$tagGroup = substr($tagGroup, strlen('tag:'));
}
$results = $query->get()->sort(function (Project\Issue $issue1, Project\Issue $issue2) use($tagGroup, $order) {
$tag1 = $issue1->tags->where('parent.id', $tagGroup, false)->first();
$tag2 = $issue2->tags->where('parent.id', $tagGroup, false)->first();
$tag1 = $tag1 ? $tag1->name : '';
$tag2 = $tag2 ? $tag2->name : '';
if ($order === 'asc') {
return strcmp($tag1, $tag2);
}
return strcmp($tag2, $tag1);
});
return $results;
}
开发者ID:oliverpool,项目名称:tinyissue,代码行数:28,代码来源:SortTrait.php
示例16: boot
/**
* Boot the application events.
*
* @return void
*/
public function boot()
{
$this->registerTranslations();
$this->registerConfig();
$this->registerViews();
StudentGrade::creating(function ($grade) {
$grade->semester_id = semester()->id;
});
Relation::morphMap(['students' => \Modules\Students\Entities\Student::class]);
}
开发者ID:hisambahaa,项目名称:DARES,代码行数:15,代码来源:StudentsServiceProvider.php
示例17: register
/**
* Register the User module service provider.
*
* @return void
*/
public function register()
{
// This service provider is a convenient place to register your modules
// services in the IoC container. If you wish, you may make additional
// methods or service providers to keep the code more focused and granular.
App::register('App\\Modules\\User\\Providers\\RouteServiceProvider');
App::register('App\\Modules\\User\\Providers\\RepositoryServiceProvider');
Relation::morphMap([config('user_module.user_types.administrator') => App\Modules\User\Models\Administrator::class]);
$this->registerNamespaces();
}
开发者ID:damnyan,项目名称:laravel,代码行数:15,代码来源:UserServiceProvider.php
示例18: register
/**
* Register any package services.
*
* @return void
*/
public function register()
{
$configPath = realpath(__DIR__ . '/../config/loggableModels.php');
$this->publishes([$configPath => $this->getConfigPath()], 'config');
$this->publishes([realpath(__DIR__ . '/../database/migrations/') => database_path('migrations')], 'migrations');
// Define Custom Polymorphic Types
Relation::morphMap([]);
$this->mergeConfigFrom($configPath, 'loggableModels');
$this->app->bind('loggable-models', function () {
return new ModelLogHandler();
});
}
开发者ID:topix-hackademy,项目名称:loggable-models,代码行数:17,代码来源:ServiceProvider.php
示例19: joinRelated
/**
* Adds a join clause to the current relatedQuery using the relation Object.
*
* @param \Illuminate\Database\Query $query
* @param \Illuminate\Database\Eloquent\Relations\Relation $relation
* @return \Illuminate\Database\Querys
*/
protected function joinRelated($query, $relation)
{
$parentTable = $relation->getParent()->getTable();
$parentKey = $relation->getParent()->getKeyName();
$relatedTable = $relation->getRelated()->getTable();
$fk = $relation->getForeignKey();
$relationType = str_replace('Illuminate\\Database\\Eloquent\\Relations\\', '', get_class($relation));
switch ($relationType) {
case 'BelongsTo':
$query->join($relatedTable, "{$relatedTable}.{$parentKey}", '=', "{$parentTable}.{$fk}");
break;
case 'HasOne':
case 'HasMany':
case 'MorphOne':
case 'MorphMany':
$query->join($relatedTable, "{$parentTable}.{$parentKey}", '=', "{$fk}");
break;
case 'BelongsToMany':
$table = $relation->getTable();
$otherKey = $relation->getOtherKey();
$query->join($table, "{$parentTable}.{$parentKey}", '=', "{$fk}")->join($relatedTable, "{$relatedTable}.{$parentKey}", '=', "{$otherKey}");
break;
default:
break;
}
return $query;
}
开发者ID:waavi,项目名称:model,代码行数:34,代码来源:Builder.php
示例20: getRelationshipWheres
/**
* Sets up the existing relationship wheres.
*
* @param \Illuminate\Database\Eloquent\Relations\Relation $relationship
* @param string $tableAlias
* @param string $pivotAlias
* @param string $pivot
*
* @return string
*/
public function getRelationshipWheres($relationship, $tableAlias, $pivotAlias = null, $pivot = null)
{
//get the relationship model
$relationshipModel = $relationship->getRelated();
//get the query instance
$query = $relationship->getQuery()->getQuery();
//get the connection instance
$connection = $query->getConnection();
//one element of the relationship query's wheres is always useless (it will say pivot_table.other_id is null)
//depending on whether or not softdeletes are enabled on the other model, this will be in either position 0
//or 1 of the wheres array
array_splice($query->wheres, method_exists($relationshipModel, 'getDeletedAtColumn') ? 1 : 0, 1);
//iterate over the wheres to properly alias the columns
foreach ($query->wheres as &$where) {
//alias the where columns
$where['column'] = $this->aliasRelationshipWhere($where['column'], $tableAlias, $pivotAlias, $pivot);
}
$sql = $query->toSql();
$fullQuery = $this->interpolateQuery($sql, $connection->prepareBindings($query->getBindings()));
$split = explode(' where ', $fullQuery);
return isset($split[1]) ? $split[1] : '';
}
开发者ID:hifone,项目名称:dashboard,代码行数:32,代码来源:Relationship.php
注:本文中的Illuminate\Database\Eloquent\Relations\Relation类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论