54 lines
1.4 KiB
PHP
54 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Domains\Bio\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Support\Str;
|
|
use Spatie\Translatable\HasTranslations;
|
|
|
|
class BioPage extends Model
|
|
{
|
|
use SoftDeletes, HasFactory, HasTranslations;
|
|
|
|
protected $guarded = ['id'];
|
|
|
|
public array $translatable = ['title', 'description'];
|
|
|
|
protected $casts = [
|
|
'theme' => 'array',
|
|
'is_published' => 'boolean',
|
|
'ulid' => 'string',
|
|
];
|
|
|
|
protected static function newFactory(): \Database\Factories\BioPageFactory
|
|
{
|
|
return \Database\Factories\BioPageFactory::new();
|
|
}
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::creating(function (self $model) {
|
|
if (empty($model->ulid)) {
|
|
$model->ulid = (string) Str::ulid();
|
|
}
|
|
});
|
|
}
|
|
|
|
public function blocks(): \Illuminate\Database\Eloquent\Relations\HasMany
|
|
{
|
|
return $this->hasMany(BioBlock::class)->orderBy('position');
|
|
}
|
|
|
|
public function workspace(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
{
|
|
return $this->belongsTo(\App\Domains\Workspace\Models\Workspace::class);
|
|
}
|
|
|
|
public function domain(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
{
|
|
return $this->belongsTo(\App\Domains\Domain\Models\Domain::class);
|
|
}
|
|
}
|