Esempio n. 1
0
 /**
  * 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;
 }
 /**
  * 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());
 }