Create complete select list from dynamically generated array

Submitted by subdesign - 9 months ago

If you have a dynamically generated list from DB, like [1 => 'First option', 2 => 'Second option', ...] use the following Collection magic to build a full select list with 'Please choose..' option at the beginning and 'Other..' option at the end.

$list = collect($this->list)->prepend('Please choose..')->push('Other')->toArray();
comments powered by Disqus