Skip to content

Instantly share code, notes, and snippets.

@imjonos
Created January 13, 2023 14:01
Show Gist options
  • Save imjonos/8adc7d3bb78a29e8247b080a9a920252 to your computer and use it in GitHub Desktop.
Save imjonos/8adc7d3bb78a29e8247b080a9a920252 to your computer and use it in GitHub Desktop.
Livewire Test
<div>
<input wire:model="search" type="text" placeholder="Search"/>
<ul>
@foreach($posts as $post)
<li>{{ $post->name }}</li>
@endforeach
</ul>
</div>
<?php
namespace App\Http\Livewire;
use App\Services\PostService;
use Illuminate\Contracts\Container\BindingResolutionException;
use Illuminate\Contracts\View\View;
use Livewire\Component;
final class SearchPosts extends Component
{
public string $search = '';
private PostService $postService;
/**
* @throws BindingResolutionException
*/
public function __construct($id = null)
{
$this->postService = app()->make(PostService::class);
parent::__construct($id);
}
public function render(): View
{
return view('livewire.search-posts', [
'posts' => $this->postService->search([
'name' => $this->search
])
]);
}
}
@livewireStyles
@livewire('search-posts')
@livewireScripts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment