resetPage(); } public function updatedStatusFilter(): void { $this->resetPage(); } public function updatedPerPage(): void { $this->resetPage(); } public function sort(string $column): void { if ($this->sortBy === $column) { $this->sortDir = $this->sortDir === 'asc' ? 'desc' : 'asc'; } else { $this->sortBy = $column; $this->sortDir = 'asc'; } } public function clearFilters(): void { $this->search = ''; $this->statusFilter = ''; $this->resetPage(); } public function with(): array { $locale = app()->getLocale(); return [ 'posts' => Post::query() ->when($this->search, fn ($q) => $q->where(function ($q) use ($locale) { $q->whereRaw("JSON_EXTRACT(title, '$.\"{$locale}\"') LIKE ?", ["%{$this->search}%"]) ->orWhereRaw("JSON_EXTRACT(title, '$.\"ar\"') LIKE ?", ["%{$this->search}%"]) ->orWhereRaw("JSON_EXTRACT(title, '$.\"en\"') LIKE ?", ["%{$this->search}%"]); })) ->when($this->statusFilter, fn ($q) => $q->where('status', $this->statusFilter)) ->orderBy($this->sortBy, $this->sortDir) ->paginate($this->perPage), 'statuses' => PostStatus::cases(), ]; } }; ?>
{{ __('posts.posts') }}

{{ __('posts.posts_description') }}

{{ __('posts.create_post') }}
@if(session('success')) {{ session('success') }} @endif @if(session('error')) {{ session('error') }} @endif
@foreach($statuses as $status) @endforeach @if($search || $statusFilter)
{{ __('common.clear') }}
@endif
@forelse($posts as $post)
{{ $post->getTitle() }}
{{ $post->getExcerpt() }}
{{ __('enums.post_status.' . $post->status->value) }}
{{ $post->updated_at->diffForHumans() }}
{{ $post->created_at->format('Y-m-d') }}
{{ __('common.edit') }}
@empty

{{ __('posts.no_posts') }}

{{ __('posts.create_post') }}
@endforelse
{{ $posts->links() }}