add id in Form :: text in laravel

2

in the inputs normally lets add an id="datum1", but if I'm occupying laravel I do it this way but it does not recognize me, what form is added in laravel since I need the input id for a script

{!! Form::text('country_destino',null,['class'=>'form-control','name'=>'country_destino','id'=>'country_destino']) !!}
    
asked by Lupitha Yañez C. 01.11.2017 в 05:51
source

2 answers

1

It's the right way, you can see it in the source code of Laravel Collective's Form Builder.

This is the code that generates the input of the form. link

/**
 * Create a form input field.
 *
 * @param  string $type
 * @param  string $name
 * @param  string $value
 * @param  array  $options
 *
 * @return \Illuminate\Support\HtmlString
 */
public function input($type, $name, $value = null, $options = [])
{
    $this->type = $type;

    if (! isset($options['name'])) {
        $options['name'] = $name;
    }

    // We will get the appropriate value for the given field. We will look for the
    // value in the session for the value in the old input data then we'll look
    // in the model instance if one is set. Otherwise we will just use empty.
    $id = $this->getIdAttribute($name, $options);

    if (! in_array($type, $this->skipValueTypes)) {
        $value = $this->getValueAttribute($name, $value);
    }

    // Once we have the type, value, and ID we can merge them into the rest of the
    // attributes array so we can convert them into their HTML attribute format
    // when creating the HTML element. Then, we will return the entire input.

    $merge = compact('type', 'value', 'id');

    $options = array_merge($options, $merge);

    return $this->toHtmlString('<input' . $this->html->attributes($options) . '>');
}

This is the code that gets the id attribute of the options (third parameter that you pass) or of the name (first parameter):

/**
 * Get the ID attribute for a field name.
 *
 * @param  string $name
 * @param  array  $attributes
 *
 * @return string
 */
public function getIdAttribute($name, $attributes)
{
    if (array_key_exists('id', $attributes)) {
        return $attributes['id'];
    }

    if (in_array($name, $this->labels)) {
        return $name;
    }
}
    
answered by 01.11.2017 / 06:00
source
-1

try it and it works properly, it must be something extra that you have, or you will be confusing yourself

Edited

It is not necessary to add the name , it is the first parameter, it would be like this:

{!! Form::text('country_destino',null,['class'=>'form-control','id'=>'country_destino']) !!}
    
answered by 01.11.2017 в 06:01