Laravel:具有分页的访问器
我有一些关于商店、餐馆和旅行(旅游套餐)多态关系的提示 我正在尝试获取用户给出的所有评论,以及为了什么 我添加了一个访问器:Laravel:具有分页的访问器,laravel,laravel-5,pagination,Laravel,Laravel 5,Pagination,我有一些关于商店、餐馆和旅行(旅游套餐)多态关系的提示 我正在尝试获取用户给出的所有评论,以及为了什么 我添加了一个访问器: public function getHeadlineAttribute($value) { $class = get_class($this->tippable); switch ($class){ case 'App\Shop': case 'App\Restaurant': return $this-&g
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()->带('headline')->分页(5)代码>
我知道我不能用“with”作为访问者。还有其他方法吗?将$appends
参数添加到Tip类中。你不需要做任何其他事情
class Tip extends Model
{
protected $appends = ['headline'];
}
是的。你比我快:D