我有两个问题/帮助解决这里:
$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);
}
1.改变这个:
$this->all()->lists('name', 'id')->all()
至:
$this->all()->lists('name', id)
你不能这样做。使用带有闭包的sortBy()
和sortByDesc()
集合方法:
->sortBy(function($i) {
return $i->name;
});