Differences between Form :: model and Form :: open?

1

Good afternoon, I am learning laravel and when using the laravel collecitve library, when creating forms, I see that sometimes the form opens with Form::model and others with Form::open . As much as I look for I can not find the difference or if there are more types and if so, when is each used? Thanks

    
asked by jlgf 11.09.2017 в 20:39
source

1 answer

1

The difference is that with Form::model you will receive the information of the model that you pass as the first parameter and therefore if Laravel finds a match between the name of the field in the model and in the form, then the form field is "filled" with the value stored in the model. Form::model also takes the values of the session that have the same names as the fields in the form.

As we can see in the code below, Form::model calls Form::open as well:

/**
 * Create a new model based form builder.
 *
 * @param  mixed $model
 * @param  array $options
 *
 * @return \Illuminate\Support\HtmlString
 */
public function model($model, array $options = [])
{
    $this->model = $model;

    return $this->open($options);
}
    
answered by 11.09.2017 / 21:00
source