lk.zachem.info/app/Modules/Post/Http/Livewire/PostsList.php
2025-04-21 18:46:13 +08:00

38 lines
797 B
PHP

<?php
namespace Modules\Post\Http\Livewire;
use Livewire\Component;
use Illuminate\Support\Facades\Storage;
use Modules\Post\Models\Post;
class PostsList extends Component
{
public $count;
public $category;
public function mount()
{
}
public function open($id)
{
$this->dispatch('showPostCardInModal', id: $id);
}
public function render()
{
$posts = Post::orderBy('id', 'desc');
if ($this->category && $this->category != 'all')
$posts = $posts->where('category', $this->category);
if ($this->count)
$posts = $posts->take($this->count)->get();
else
$posts = $posts->take(10)->get();
return view('post::list.cards', [
'posts' => $posts
]);
}
}