Entity
Entity inherits all functionality from Choice type, with additional options:
class
(String) (Default:null
) - Full path to the Model class that will be used to fetch choices.query_builder
(Closure) (Default:null
) - If provided, used to filter data before setting as choices. If null, gets all data.property
(String) (Default:name
) - Property from model that will be used as label for options in choicesproperty_key
(String) (Default:id
) - Property from model that will be used as value for options in choices
Note: If choices
are provided in options, class
option is ignored, and passed data for choices
is used.
<?php
$this->add('languages', 'entity', [
'class' => 'App\Language',
'property' => 'short_name',
'query_builder' => function (App\Language $lang) {
// If query builder option is not provided, all data is fetched
return $lang->where('active', 1);
}
]);