Reputation: 75
I'm creating search engine and i want to create select with all providers of an item by
controller:
$this->view->providers = Provider::find(["order"=>"name"]);
view:
{{ select("searchProvider", providers, "class":"form-control", "using":["id", "name"]) }}
but how to add to this select "all providers" option?
Upvotes: 1
Views: 405
Reputation: 1966
Since you are already using Volt tag helpers, then the easiest way to accomplish what you want is to add three new arguments to the select() function:
{{ select("searchProvider", providers, "class":"form-control", "using":["id", "name"], "useEmpty":true, "emptyText":"all providers", "emptyValue":"") }}
Here you are designating an 'empty' select option with the text that you want and an empty value. Then in your controller, you can execute code depending on whether searchProvider
is empty or not. Just be very careful with those values returned in the form. But form validation and sanitation is another topic.
Upvotes: 1