【发布时间】:2018-02-10 06:59:42
【问题描述】:
我在与 Shops、Restaurants 和 Trips 的多态关系方面有一些提示(对于旅游套餐)。
我正在尝试获取用户给出的所有评论,以及为了什么。
我添加了一个访问器:
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 '';
}
}
并且想获取如下内容:
$user->tips()->with('headline')->paginate(5);
我知道我不能将“with”用于访问器。还有什么办法吗?
【问题讨论】:
标签: laravel laravel-5 pagination