php - Laravel 4.2 Dropdown List -
i want populate select input using data stored in database.
i have firstname , lastname fields clients , want display fullname (both firstname , lastname) on dropdown list.
i'm using client::lists('firstname', 'id')
generate list. apparently show firstname only.
how combine 2 fields in above code, or there better alternative this?
another related question, how set first option --please select client-- instead of getting first client straight away on top.
you define accessor adding following code user model
public function getusernameattribute() { return "{$this->lastname} {$this->firstname}"; }
and query model way
$list = user::get(['firstname','lastname','id'])->lists('username','id');
regard --please select client-- ,
you may array merge or plus so
form::select('list',['0'=>'--please select client--'] + $list);
Comments
Post a Comment