post = $post; $this->title_ar = $post->title['ar'] ?? ''; $this->title_en = $post->title['en'] ?? ''; $this->body_ar = $post->body['ar'] ?? ''; $this->body_en = $post->body['en'] ?? ''; $this->status = $post->status->value; } public function rules(): array { return [ 'title_ar' => ['required', 'string', 'max:255'], 'title_en' => ['required', 'string', 'max:255'], 'body_ar' => ['required', 'string'], 'body_en' => ['required', 'string'], 'status' => ['required', 'in:draft,published'], ]; } public function messages(): array { return [ 'title_ar.required' => __('posts.title_ar_required'), 'title_en.required' => __('posts.title_en_required'), 'body_ar.required' => __('posts.body_ar_required'), 'body_en.required' => __('posts.body_en_required'), ]; } public function save(): void { $validated = $this->validate(); $oldValues = $this->post->toArray(); $this->post->update([ 'title' => [ 'ar' => $validated['title_ar'], 'en' => $validated['title_en'], ], 'body' => [ 'ar' => clean($validated['body_ar']), 'en' => clean($validated['body_en']), ], 'status' => $validated['status'], 'published_at' => $validated['status'] === 'published' && ! $this->post->published_at ? now() : $this->post->published_at, ]); AdminLog::create([ 'admin_id' => auth()->id(), 'action' => 'update', 'target_type' => 'post', 'target_id' => $this->post->id, 'old_values' => $oldValues, 'new_values' => $this->post->fresh()->toArray(), 'ip_address' => request()->ip(), 'created_at' => now(), ]); session()->flash('success', __('posts.post_saved')); } public function saveDraft(): void { $this->status = 'draft'; $this->save(); } public function publish(): void { $this->status = 'published'; $this->save(); } public function autoSave(): void { if ($this->status === 'draft') { $this->post->update([ 'title' => [ 'ar' => $this->title_ar, 'en' => $this->title_en, ], 'body' => [ 'ar' => clean($this->body_ar), 'en' => clean($this->body_en), ], ]); } } public function preview(): void { $this->showPreview = true; } public function closePreview(): void { $this->showPreview = false; } public function delete(): void { $this->showDeleteModal = true; } public function confirmDelete(): void { AdminLog::create([ 'admin_id' => auth()->id(), 'action' => 'delete', 'target_type' => 'post', 'target_id' => $this->post->id, 'old_values' => $this->post->toArray(), 'ip_address' => request()->ip(), 'created_at' => now(), ]); $this->post->delete(); session()->flash('success', __('posts.post_deleted')); $this->redirect(route('admin.posts.index'), navigate: true); } public function cancelDelete(): void { $this->showDeleteModal = false; } }; ?>
{{ __('posts.back_to_posts') }}
{{ __('posts.edit_post') }}

{{ __('posts.last_updated') }}: {{ $post->updated_at->diffForHumans() }} @if($status === 'draft') ({{ __('posts.auto_save_enabled') }}) @endif

{{ __('enums.post_status.' . $status) }}
@if(session('success')) {{ session('success') }} @endif
{{ __('posts.arabic_content') }} {{ __('posts.title') }} ({{ __('posts.arabic') }}) {{ __('posts.body') }} ({{ __('posts.arabic') }})
{{ __('posts.english_content') }} {{ __('posts.title') }} ({{ __('posts.english') }}) {{ __('posts.body') }} ({{ __('posts.english') }})
{{ __('posts.delete_post') }}
{{ __('common.cancel') }} {{ __('posts.preview') }} @if($status === 'published') {{ __('posts.unpublish') }} {{ __('posts.save_changes') }} @else {{ __('posts.save_draft') }} {{ __('posts.publish') }} @endif
{{-- Preview Modal --}}
{{ __('posts.preview') }}

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

{{ $title_ar }}

{!! clean($body_ar) !!}

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

{{ $title_en }}

{!! clean($body_en) !!}
{{ __('common.close') }}
{{-- Delete Confirmation Modal --}}
{{ __('posts.delete_post') }} {{ __('posts.delete_post_warning') }}

{{ __('posts.deleting_post', ['title' => $post->getTitle()]) }}

{{ __('common.cancel') }} {{ __('posts.delete_permanently') }}
@push('styles') @endpush @push('scripts') @endpush