0

I am working in:

Livewire 3, Laravel version is 10.10, PHP 8.2.4

I am trying to bind simple data with simple code but its not working, I am not sure why? Can you please help me? Livewire actions functions on click working, but data binding not updating data while typing in input field.

user.blade.php

<div>
    <input type="text" wire:model="name" id="description">
    Hi! My name is {{ $name }}
    <script>
        console.log("Livewire JavaScript loaded and working!");
    </script>
</div>

User.Php

namespace App\Livewire;

use Livewire\Component;

class User extends Component
{

    public $name = 'ali';


    public function render()
    {

        return view('livewire.user');
    }
}

On page load Output shows "ali" in the input field, but when I type more characters in input fields its not updating variable value.

Tim Lewis
  • 27,813
  • 13
  • 73
  • 102
Moon
  • 3
  • 3

2 Answers2

0

In the documentation you can read : By default, Livewire only sends a network request when the form is submitted (or any other action is called), not while the form is being filled out.

change your input code as below :

<input type="text" wire:model.live="name" id="description">

  • You are right. Thank you very much now it's working. I really appreciate it. – Moon Jul 25 '23 at 10:55
  • i have one more question i am learning $queryString for search. now when filling in the search bar its updating link live but the record not updating live, but when i refresh page then record updates according to the search query, its means my query is correct the problem is why its not update without reloading page..
    @foreach($users as $user) @endforeach
    {{$user->id}} {{$user->name}} {{$user->email}}
    – Moon Jul 25 '23 at 11:19
  • public $search; protected $queryString = ['search']; public function render() { $users = \App\Models\User::query() ->where('name', 'like', '%' . $this->search . '%') ->get(); return view('livewire.user', ['users' => $users]); } – Moon Jul 25 '23 at 11:20
  • oops, this was due to in table record not updating when I tried
      it updating live records thank you.
    – Moon Jul 25 '23 at 11:34
-2

Did you include your livewire script or load unless include it by

@livewireScripts

add it to your main/master blade file. Also, try clearing all cache by

php artisan optimize:clear
Wakil Ahmed
  • 1,053
  • 1
  • 8
  • 16
  • 1
    This should be a comment, not an answer. If you need to ask for clarification, or make a suggestion, please do it as a comment. – Tim Lewis Jul 24 '23 at 16:50
  • Hi, @livewireScripts automatically loading in livewire 3 from layouts/app.blade.php I have checked the script from "view source page" livewireScripts successfully loading by default. – Moon Jul 24 '23 at 17:58
  • i think the ajax request are not working properly, – Moon Jul 24 '23 at 18:09