It seems like you're encountering an issue with Livewire's wire:model.live directive. The wire:model.live directive is not a standard Livewire directive. Instead, Livewire provides wire:model for two-way data binding and wire:model.lazy for updating the data when the input loses focus.
If you want to search for a post by its ID as the user types, you should use wire:model combined with the updated lifecycle hook to react to changes. Here's how you can modify your code:
First, change wire:model.live to wire:model in your input field:
<input type="text" name="id" wire:model="id">
Next, in your Livewire component, you can use the updated method to react to changes in the $id property. This method is called every time a property that is bound to the view using wire:model is updated:
public function updated($propertyName)
{
if ($propertyName === 'id' && is_numeric($this->id)) {
// Perform your search logic here
// For example, you can call a method that updates the list of videos
$this->searchVideosById();
}
}
public function searchVideosById()
{
// Your search logic here
// This is just an example, you'll need to implement the actual logic
$this->videos = Video::where('id', $this->id)->get();
}
Make sure to remove the dump($this->validate()); call from your render method, as it's not a good practice to have debugging code in your production code.
Also, ensure that your validation rules are correctly defined. The #[Validate('numeric')] attribute syntax is not standard PHP or Livewire syntax. Livewire uses a different approach for validation. Here's an example of how you might validate the $id property:
protected $rules = [
'id' => 'numeric',
// ... other rules
];
public function updatedId()
{
$this->validateOnly('id');
// Perform the search or other actions after validation
}
Remember to import the necessary classes at the top of your Livewire component file:
use Livewire\Component;
use Livewire\WithPagination;
use App\Models\Video;
// ... other necessary imports
With these changes, your Livewire component should update the list of videos as the user types an ID into the input field, assuming that the searchVideosById method contains the correct logic to perform the search.