【发布时间】:2016-08-14 23:53:38
【问题描述】:
我有一个模型,我需要检查它的值并返回一个不健康的状态。我创建了一个访问器,它正在工作并按预期返回 true 或 false。
$task->unhealthy()
访问代码
public function getUnhealthyAttribute(){
//Is in Active status
if ( $this->status_id == 1 ){
return true;
}
//Has overdue items
if ( $this->items()->overdue()->count() > 0 ) {
return true;
}
return false;
}
我现在需要检索所有“不健康”任务的集合。
问题:是否可以通过范围利用我的访问器?什么是正确的方法?
【问题讨论】:
标签: laravel scope eloquent accessor