{"id":246,"date":"2016-02-11T07:19:42","date_gmt":"2016-02-11T07:19:42","guid":{"rendered":"https:\/\/vining.in\/blog\/?p=246"},"modified":"2017-05-27T12:04:34","modified_gmt":"2017-05-27T12:04:34","slug":"populating-a-dropdown-menu-with-database-results-in-laravel-with-empty-option-in-formselect-with-lists","status":"publish","type":"post","link":"https:\/\/vining.in\/blog\/populating-a-dropdown-menu-with-database-results-in-laravel-with-empty-option-in-formselect-with-lists\/","title":{"rendered":"Populating a dropdown menu with database results in Laravel with empty option in Form::select with lists()"},"content":{"rendered":"<p>In order to populate a dropdown menu with all the records from the Category Model, you can do the following, in your blade (view) file:<\/p>\n<pre class=\"lang:php decode:true\">{{ Form::select('drpCatg', \\App\\Category::lists('category_name', 'id')) }}<\/pre>\n<p>If you want to add empty or &#8216;&#8212; Select Category &#8212;&#8216; option first, you can do the following, in your blade (view) file:<\/p>\n<p>If you are trying to following code and getting error &#8220;Unsupported operand type&#8221;<\/p>\n<pre class=\"lang:default decode:true \">{{ Form::select('drpCatg', ['0' =&gt; 'Select'] + \\App\\Category::lists('category_name', 'id')) }}\r\n<\/pre>\n<p>Replace above code with<\/p>\n<pre class=\"lang:default decode:true \">{{ Form::select('drpCatg', ['0' =&gt; 'Select'] + \\App\\Category::lists('category_name', 'id')-&gt;all() }}\r\n<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In order to populate a dropdown menu with all the records from the Category Model, you can do the following, in your blade (view) file: {{ Form::select(&#8216;drpCatg&#8217;, \\App\\Category::lists(&#8216;category_name&#8217;, &#8216;id&#8217;)) }} If you want to add empty or &#8216;&#8212; Select Category &#8212;&#8216; option first, you can do the following, in your blade (view) file: If you [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27],"tags":[63,64,65],"class_list":["post-246","post","type-post","status-publish","format-standard","hentry","category-laravel","tag-dropdopdown-in-laravel","tag-easy-dropdowns-with-eloquents-lists-method","tag-empty-option-in-formselect-with-lists"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v23.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Populating a dropdown menu with database results in Laravel with empty option in Form::select with lists() - Programmer Code<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/vining.in\/blog\/populating-a-dropdown-menu-with-database-results-in-laravel-with-empty-option-in-formselect-with-lists\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Populating a dropdown menu with database results in Laravel with empty option in Form::select with lists() - Programmer Code\" \/>\n<meta property=\"og:description\" content=\"In order to populate a dropdown menu with all the records from the Category Model, you can do the following, in your blade (view) file: {{ Form::select(&#039;drpCatg&#039;, AppCategory::lists(&#039;category_name&#039;, &#039;id&#039;)) }} If you want to add empty or &#8216;&#8212; Select Category &#8212;&#8216; option first, you can do the following, in your blade (view) file: If you [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/vining.in\/blog\/populating-a-dropdown-menu-with-database-results-in-laravel-with-empty-option-in-formselect-with-lists\/\" \/>\n<meta property=\"og:site_name\" content=\"Programmer Code\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/vining.in\" \/>\n<meta property=\"article:published_time\" content=\"2016-02-11T07:19:42+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-05-27T12:04:34+00:00\" \/>\n<meta name=\"author\" content=\"codeadmin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"codeadmin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/vining.in\/blog\/populating-a-dropdown-menu-with-database-results-in-laravel-with-empty-option-in-formselect-with-lists\/\",\"url\":\"https:\/\/vining.in\/blog\/populating-a-dropdown-menu-with-database-results-in-laravel-with-empty-option-in-formselect-with-lists\/\",\"name\":\"Populating a dropdown menu with database results in Laravel with empty option in Form::select with lists() - Programmer Code\",\"isPartOf\":{\"@id\":\"https:\/\/vining.in\/blog\/#website\"},\"datePublished\":\"2016-02-11T07:19:42+00:00\",\"dateModified\":\"2017-05-27T12:04:34+00:00\",\"author\":{\"@id\":\"https:\/\/vining.in\/blog\/#\/schema\/person\/cda9f07adf3479ac270e2320a914552e\"},\"breadcrumb\":{\"@id\":\"https:\/\/vining.in\/blog\/populating-a-dropdown-menu-with-database-results-in-laravel-with-empty-option-in-formselect-with-lists\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/vining.in\/blog\/populating-a-dropdown-menu-with-database-results-in-laravel-with-empty-option-in-formselect-with-lists\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/vining.in\/blog\/populating-a-dropdown-menu-with-database-results-in-laravel-with-empty-option-in-formselect-with-lists\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/vining.in\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Populating a dropdown menu with database results in Laravel with empty option in Form::select with lists()\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/vining.in\/blog\/#website\",\"url\":\"https:\/\/vining.in\/blog\/\",\"name\":\"Programmer Code\",\"description\":\"- Where Developers Learn, Share, &amp; Build Careers\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/vining.in\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/vining.in\/blog\/#\/schema\/person\/cda9f07adf3479ac270e2320a914552e\",\"name\":\"codeadmin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/vining.in\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/770f5bb2b95d41f98f29e7251fb1873b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/770f5bb2b95d41f98f29e7251fb1873b?s=96&d=mm&r=g\",\"caption\":\"codeadmin\"},\"url\":\"https:\/\/vining.in\/blog\/author\/codeadmin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Populating a dropdown menu with database results in Laravel with empty option in Form::select with lists() - Programmer Code","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/vining.in\/blog\/populating-a-dropdown-menu-with-database-results-in-laravel-with-empty-option-in-formselect-with-lists\/","og_locale":"en_US","og_type":"article","og_title":"Populating a dropdown menu with database results in Laravel with empty option in Form::select with lists() - Programmer Code","og_description":"In order to populate a dropdown menu with all the records from the Category Model, you can do the following, in your blade (view) file: {{ Form::select('drpCatg', AppCategory::lists('category_name', 'id')) }} If you want to add empty or &#8216;&#8212; Select Category &#8212;&#8216; option first, you can do the following, in your blade (view) file: If you [&hellip;]","og_url":"https:\/\/vining.in\/blog\/populating-a-dropdown-menu-with-database-results-in-laravel-with-empty-option-in-formselect-with-lists\/","og_site_name":"Programmer Code","article_publisher":"https:\/\/www.facebook.com\/vining.in","article_published_time":"2016-02-11T07:19:42+00:00","article_modified_time":"2017-05-27T12:04:34+00:00","author":"codeadmin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"codeadmin","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/vining.in\/blog\/populating-a-dropdown-menu-with-database-results-in-laravel-with-empty-option-in-formselect-with-lists\/","url":"https:\/\/vining.in\/blog\/populating-a-dropdown-menu-with-database-results-in-laravel-with-empty-option-in-formselect-with-lists\/","name":"Populating a dropdown menu with database results in Laravel with empty option in Form::select with lists() - Programmer Code","isPartOf":{"@id":"https:\/\/vining.in\/blog\/#website"},"datePublished":"2016-02-11T07:19:42+00:00","dateModified":"2017-05-27T12:04:34+00:00","author":{"@id":"https:\/\/vining.in\/blog\/#\/schema\/person\/cda9f07adf3479ac270e2320a914552e"},"breadcrumb":{"@id":"https:\/\/vining.in\/blog\/populating-a-dropdown-menu-with-database-results-in-laravel-with-empty-option-in-formselect-with-lists\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/vining.in\/blog\/populating-a-dropdown-menu-with-database-results-in-laravel-with-empty-option-in-formselect-with-lists\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/vining.in\/blog\/populating-a-dropdown-menu-with-database-results-in-laravel-with-empty-option-in-formselect-with-lists\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/vining.in\/blog\/"},{"@type":"ListItem","position":2,"name":"Populating a dropdown menu with database results in Laravel with empty option in Form::select with lists()"}]},{"@type":"WebSite","@id":"https:\/\/vining.in\/blog\/#website","url":"https:\/\/vining.in\/blog\/","name":"Programmer Code","description":"- Where Developers Learn, Share, &amp; Build Careers","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/vining.in\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/vining.in\/blog\/#\/schema\/person\/cda9f07adf3479ac270e2320a914552e","name":"codeadmin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/vining.in\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/770f5bb2b95d41f98f29e7251fb1873b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/770f5bb2b95d41f98f29e7251fb1873b?s=96&d=mm&r=g","caption":"codeadmin"},"url":"https:\/\/vining.in\/blog\/author\/codeadmin\/"}]}},"_links":{"self":[{"href":"https:\/\/vining.in\/blog\/wp-json\/wp\/v2\/posts\/246","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vining.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vining.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vining.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vining.in\/blog\/wp-json\/wp\/v2\/comments?post=246"}],"version-history":[{"count":4,"href":"https:\/\/vining.in\/blog\/wp-json\/wp\/v2\/posts\/246\/revisions"}],"predecessor-version":[{"id":324,"href":"https:\/\/vining.in\/blog\/wp-json\/wp\/v2\/posts\/246\/revisions\/324"}],"wp:attachment":[{"href":"https:\/\/vining.in\/blog\/wp-json\/wp\/v2\/media?parent=246"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vining.in\/blog\/wp-json\/wp\/v2\/categories?post=246"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vining.in\/blog\/wp-json\/wp\/v2\/tags?post=246"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}