Initial commit
This commit is contained in:
52
app/Models/NewsPost.php
Normal file
52
app/Models/NewsPost.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?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';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user