Search code examples
laravel-livewirelaravel-8laravel-jetstream

Input Value not working with Livewire wire:model


What I am trying to do is getting some data from DB and showing it in Input Value fields but here the problem is that when I use wire:model='some_input_name' the value does not show up. And if I remove the wire:model it shows the value

the code:

<div class="form-group">
    <label for="site_name">Site Name</label>
    <input wire:model='site_name' type="text" name="site_name" id="site_name"
          class="form-control"
          placeholder="Site Name" value="{{$settings->site_name}}">
    </div>

Is there anything wrong here?? What is the correct way to show value while binding the input field with livewire component?


Solution

  • Remove value="{{ $settings->site_name }}" from your <input>, and use the following code in your component's mount() method:

    $this->site_name = $settings->site_name;
    

    This will preserve the two-way data binding, whilst letting you set an initial value.