Skip to content

Laravel – Dropdowns with Collection’s Lists method

Last updated on February 17, 2018

The Collection class in Laravel is really awesome. In Laravel, Eloquent returns result in the collection object. The class contains a lot of handy methods that will make your work so much easier. In this post I would like to write about List() method and I show you , how I used list method to generate HTML dropdown with laravel form collective .

list() method will return every value of a given key. The following example returns every category’s title, indexed by their category id.

// Here Category is model name
$categories = Category::lists('title', 'id'); 

Generating A Drop-Down List


$categories = Category::lists('title', 'id');
echo Form::select('category_id', $categories);

4 1 vote
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments