18 lines
1013 B
PHP
18 lines
1013 B
PHP
<?php
|
|
namespace Modules\Content\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
final class ContentDocument extends Model
|
|
{
|
|
use SoftDeletes;
|
|
protected $fillable = ['content_type_id','title','slug','data','status','published_at','expires_at','language','created_by','updated_by'];
|
|
protected function casts(): array { return ['data'=>'array','published_at'=>'datetime','expires_at'=>'datetime']; }
|
|
public function type(): BelongsTo { return $this->belongsTo(ContentType::class, 'content_type_id'); }
|
|
public function placements(): HasMany { return $this->hasMany(PageContent::class); }
|
|
public function scopePublished($query) { return $query->where('status','published')->where(fn($q) => $q->whereNull('published_at')->orWhere('published_at','<=',now()))->where(fn($q) => $q->whereNull('expires_at')->orWhere('expires_at','>',now())); }
|
|
}
|