【发布时间】:2018-01-02 18:42:56
【问题描述】:
我有两个问题/帮助在这里解决:
- 如何减少这行代码中的冗余
$this->all()->lists('name', 'id')->all() - 如何使用
orderBy方法调用mutator。
helper.php
if (! function_exists('withEmpty')) {
function withEmpty($selectList, $emptyLabel = '')
{
return array('' => $emptyLabel) + $selectList;
}
}
Agent.php(模型)
public function getNameAttribute($value){
return $this->lname.', '.$this->fname.' '.$this->mname;
}
public function listAgents($emptyLabel = '--Select Agent--'){
return withEmpty($this->all()->lists('name', 'id')->all(), $emptyLabel);
}
【问题讨论】:
标签: php laravel laravel-5.1