protonemedia / laravel-form-components

A set of Blade components to rapidly build forms with Tailwind CSS (v1.0 and v2.0) and Bootstrap 4/5. Supports validation, model binding, default values, translations, Laravel Livewire, includes default vendor styling and fully customizable!
https://protone.media/blog/laravel-form-components-to-rapidly-build-forms-with-tailwind-css-and-bootstrap-4
MIT License
814 stars 104 forks source link

How to mark the selected option in a select when editing a form? #67

Closed alexv96 closed 3 years ago

alexv96 commented 3 years ago

I am working with bootstrap 4, the issue is that I have a form that is edit and always in the select I select the first option instead of editing me to mark the selected option and registered in the database.

Am I missing some other attribute or not?

Controller
    public function chooseTenant(){
        $tenants = Auth::user()->tenants->pluck('name','id');
        return view('switchAccount',['model'=>$tenants]);
    }
View
<x-form :action="route('choose_account')">
  <x-form-select name="tenant" :options="$model" :bind="4" label="{{__('Company')}}" />
  <x-form-submit>
        {{__('Cambiar cuenta')}}
  </x-form-submit>
</x-form>
pascalbaljet commented 3 years ago

You should use :default="4" instead of :bind="4"