83 lines
1.9 KiB
PHP
83 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Traits\Models\HasActivityLog;
|
|
use App\Traits\Models\IsCachedAsCollection;
|
|
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\Support\Carbon;
|
|
|
|
/**
|
|
* FaqQuestion.
|
|
*
|
|
* @property string $question Question
|
|
* @property string $answer Answer
|
|
* @property-read Carbon $created_at Creation Date.
|
|
* @property-read Carbon $updated_at Last update Date.
|
|
* @property-read FaqTheme $theme Associated theme.
|
|
* @property-read \App\Models\ActivityLog $activityLogs Activities logs One-to-many relationship.
|
|
*/
|
|
class FaqQuestion extends Model
|
|
{
|
|
use HasActivityLog;
|
|
use HasFactory;
|
|
use IsCachedAsCollection;
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var list<string>
|
|
*/
|
|
#[\Override]
|
|
protected $fillable = [
|
|
'question',
|
|
'answer',
|
|
'theme_id',
|
|
];
|
|
|
|
/**
|
|
* The relations to eager load on every query.
|
|
*
|
|
* @var list<string>
|
|
*/
|
|
#[\Override]
|
|
protected $with = ['theme'];
|
|
|
|
// * EVENTS
|
|
|
|
/**
|
|
* Perform any actions required after the model boots.
|
|
*/
|
|
protected static function booted(): void
|
|
{
|
|
static::created(fn () => self::removeCached());
|
|
static::updated(fn () => self::removeCached());
|
|
static::deleted(fn () => self::removeCached());
|
|
}
|
|
|
|
// * RELATIONS
|
|
/**
|
|
* Theme relation
|
|
*
|
|
* @return BelongsTo<FaqTheme, $this>
|
|
*/
|
|
public function theme(): BelongsTo
|
|
{
|
|
return $this->belongsTo(FaqTheme::class, 'theme_id');
|
|
}
|
|
|
|
/**
|
|
* Activities logs One-to-many relationship.
|
|
*
|
|
* @return HasMany<ActivityLog, $this>
|
|
*/
|
|
public function activityLogs(): HasMany
|
|
{
|
|
return $this->hasMany(ActivityLog::class);
|
|
}
|
|
}
|