Files
vkv/app/Models/NewsPost.php
Zdeněk Burda 41e3ce6f25 Initial commit
2026-01-09 21:26:40 +01:00

53 lines
1.1 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Spatie\Translatable\HasTranslations;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
//use App\Policies\NewsPostPolicy;
//use Illuminate\Database\Eloquent\Attributes\UsePolicy;
//#[UsePolicy(NewsPostPolicy::class)]
class NewsPost extends Model
{
use HasFactory;
use HasTranslations;
protected $table = 'news_posts';
public array $translatable = [
'title',
'content',
'excerpt'
];
protected $fillable = [
'title',
'slug',
'content',
'excerpt',
'is_published',
'published_at',
'author_id',
];
protected $casts = [
'is_published' => 'boolean',
'published_at' => 'datetime',
'author_id' => 'integer',
];
public function author(): BelongsTo
{
return $this->belongsTo(User::class, 'author_id');
}
// route model binding přes slug (pro /api/news/{slug})
public function getRouteKeyName(): string
{
return 'slug';
}
}