69 lines
1.6 KiB
PHP
69 lines
1.6 KiB
PHP
<?php declare(strict_types=1);
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Models\Scopes\SortScope;
|
|
use Illuminate\Database\Eloquent\Attributes\ScopedBy;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
#[ScopedBy([SortScope::class])]
|
|
final class Documentation extends Model
|
|
{
|
|
use HasFactory, SoftDeletes;
|
|
|
|
protected $table = 'documentation';
|
|
|
|
/**
|
|
* The model's default values for attributes.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $attributes = [
|
|
'sort' => 100,
|
|
'is_public' => true,
|
|
];
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $fillable = [
|
|
'slug',
|
|
'is_public',
|
|
'category_id',
|
|
];
|
|
|
|
/**
|
|
* Get the attributes that should be cast.
|
|
*
|
|
* @return array<string, string>
|
|
*/
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'is_public' => 'boolean',
|
|
];
|
|
}
|
|
|
|
public function category(): BelongsTo
|
|
{
|
|
return $this->belongsTo(DocumentationCategory::class, 'category_id', 'id');
|
|
}
|
|
|
|
public function contents(): HasMany
|
|
{
|
|
return $this->hasMany(DocumentationContent::class, 'documentation_id', 'id');
|
|
}
|
|
|
|
public function content(): HasOne
|
|
{
|
|
return $this->hasOne(DocumentationContent::class, 'documentation_id', 'id');
|
|
}
|
|
}
|