completed story 1.1 with QA tests and fixes

This commit is contained in:
Naser Mansour
2025-12-26 13:46:39 +02:00
parent 028ce573b9
commit 84d9c2f66a
57 changed files with 2193 additions and 85 deletions
+65
View File
@@ -0,0 +1,65 @@
<?php
namespace App\Models;
use App\Enums\PostStatus;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
use HasFactory;
protected $fillable = [
'title',
'body',
'status',
'published_at',
];
protected function casts(): array
{
return [
'title' => 'array',
'body' => 'array',
'status' => PostStatus::class,
'published_at' => 'datetime',
];
}
/**
* Scope to filter published posts.
*/
public function scopePublished($query)
{
return $query->where('status', PostStatus::Published);
}
/**
* Scope to filter draft posts.
*/
public function scopeDraft($query)
{
return $query->where('status', PostStatus::Draft);
}
/**
* Get the title in the specified locale, with fallback to Arabic.
*/
public function getTitle(?string $locale = null): string
{
$locale ??= app()->getLocale();
return $this->title[$locale] ?? $this->title['ar'] ?? '';
}
/**
* Get the body in the specified locale, with fallback to Arabic.
*/
public function getBody(?string $locale = null): string
{
$locale ??= app()->getLocale();
return $this->body[$locale] ?? $this->body['ar'] ?? '';
}
}