本文整理汇总了PHP中Illuminate\Database\Eloquent\Relations\Relation::get方法的典型用法代码示例。如果您正苦于以下问题:PHP Relation::get方法的具体用法?PHP Relation::get怎么用?PHP Relation::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Eloquent\Relations\Relation
的用法示例。
在下文中一共展示了Relation::get方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: makeFromRelation
/**
* Make resource from an Eloquent query builder.
*
* @param \Illuminate\Database\Eloquent\Relations\Relation $relation
* @return \League\Fractal\Resource\ResourceInterface
*/
protected function makeFromRelation(Relation $relation) : ResourceInterface
{
return static::makeFromCollection($relation->get());
}