本文整理匯總了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());
}