vendredi 1 septembre 2017

Laravel: Accessors with Pagination

I have tips in a polymorphic relationship with Shops, Restaurants and Trips (for tour packages).

I am trying to fetch all reviews a user has given, and for what.

I’ve added an accessor:

public function getHeadlineAttribute($value)
{
  $class = get_class($this->tippable);

  switch ($class){
      case 'App\Shop':
      case 'App\Restaurant':

          return $this->tippable->brand->name;
      case 'App\Trip':
          return $this->tippable->from.' to '.$this->tippable->to;
      default:
          return '';

  }
}

And would like to fetch something like: $user->tips()->with('headline')->paginate(5);

I see I can’t use “with” for accessors. Any other way?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2xCQ1qj
via IFTTT

Aucun commentaire:

Enregistrer un commentaire