I have two questions/help to fix here:
- How to reduce redundancy in this line of code
$this->all()->lists('name', 'id')->all()
- How to call mutator by using
orderBy
method.
helper.php
if (! function_exists('withEmpty')) {
function withEmpty($selectList, $emptyLabel = '')
{
return array('' => $emptyLabel) + $selectList;
}
}
Agent.php (model)
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);
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire