Created
January 13, 2023 14:01
-
-
Save imjonos/8adc7d3bb78a29e8247b080a9a920252 to your computer and use it in GitHub Desktop.
Livewire Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div> | |
<input wire:model="search" type="text" placeholder="Search"/> | |
<ul> | |
@foreach($posts as $post) | |
<li>{{ $post->name }}</li> | |
@endforeach | |
</ul> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 | |
]) | |
]); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@livewireStyles | |
@livewire('search-posts') | |
@livewireScripts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment