If your form is made with Laravel collective form and you are searching for how to use the select option in laravel collective form then this tutorial is for you. In this example, I will show you laravel collective select option example. I will create a simple collective form and then I will add a select box with the user list and then we will submit it then we will return the response from the controller.

You know that Laravel collective form is a little bit different and complex than the normal HTML form. So let's see the example code of the laravel collective formselect:

laravel-collective-form-select-option-example

Laravel collective select option accepts an array. So we have to pass an array like that:

$users = User::select('id','name')->get()->pluck('name','id');

 

Now pass this in collective form like:

{!! Form::open(['route' => 'user.store', "method" => "post", "class" => "form", "id" => "createUserForm"]) !!}
    {!! Form::token() !!}
    <div class="form-group mt-3 mb-2">
        {!! Form::label("user", "Select User") !!}
        {!! Form::select('user',$users, null, ['placeholder' => 'Pick a size...']) !!}
        {!! $errors->first("user",'<span class="help-block">:message</span>') !!}
    </div>
    {!! Form::submit("Submit", ["class"=>"btn btn-primary"]) !!}
{!! Form::close() !!}

 

Read also: Laravel Collective Form Checkbox Example

 

Now if you submit this form with data then you will see the following output:

{
  "_token": "xDbOBo3TxWuc5xEbvExTv3E8lSLjiGsEdLeoqMjr",
  "user": "3"
}

 

Conclusion

Hope this how to use select option in laravel collective form tutorial will help. After completing this laravel collective select option tutorial, your concept will be clear about how to use the collective select option form in laravel. Hope this laravel collective formselect tutorial will clear your concept about laravel collective select option form.