Closed XavRsl closed 8 years ago
Hey Xavier,
If I understand the question, the easiest way to handle that is to specify your options manually:
{!!
Former
::select('my_field')
->options(RelatedModel::lists('name', 'key'))
->value($mainModel->my_field)
!!}
Hi ! Here's what I ended doing :
{!!
Former::select('recruiters')
->fromQuery($recruiters, null, 'uid_ref')
->placeholder('Sélectionnez votre recruteur pour ce centre')
->addClass('chosen-select')
!!}
And in the model :
function __toString()
{
$name = $this->prenom . ' ' . $this->nom_usuel;
$name .= ($this->nom_usuel == $this->nom_patronymique) ? '' : ' (' . $this->nom_patronymique . ')';
return $name;
}
According to the docs, I could have used a public static property called $key containing 'uid_ref' in order to avoid the relatively ugly fromQuery($recruiters, null, 'uid_ref')
I've tried with options, value and the lot, but can't make it work properly...
Thanks for your help Claar !!
Xavier
No problem, glad you got it worked out.
Hi, I'm trying to use former select in a situation where I have a related hasOne model that holds the 'name' value of the select, and a specific field on my main model that I want to use as 'value'. In the docs, it says that we can add elements on the model to achieve this :
works fine. But, setting a static public $key that holds the name of the field containing the select 'value' doesn't work. Am I doing something wrong ?
Thanks.
Xavier