68 lines
1.5 KiB
PHP
68 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Traits\Models\IsCachedAsCollection;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
/**
|
|
* FaqQuestion.
|
|
*
|
|
* @property string $question Question
|
|
* @property string $answer Answer
|
|
* @property-read \Illuminate\Support\Carbon $created_at Creation Date.
|
|
* @property-read \Illuminate\Support\Carbon $updated_at Last update Date.
|
|
*
|
|
* @property-read \App\Models\FaqTheme $theme Associated theme.
|
|
*/
|
|
class FaqQuestion extends Model
|
|
{
|
|
use HasFactory;
|
|
use IsCachedAsCollection;
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array<string>
|
|
*/
|
|
protected $fillable = [
|
|
'question',
|
|
'answer',
|
|
'theme_id'
|
|
];
|
|
|
|
/**
|
|
* The relations to eager load on every query.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $with = ['theme'];
|
|
|
|
// * EVENTS
|
|
|
|
/**
|
|
* Perform any actions required after the model boots.
|
|
*
|
|
* @return void
|
|
*/
|
|
protected static function booted()
|
|
{
|
|
static::created(fn () => self::removeCached());
|
|
static::updated(fn () => self::removeCached());
|
|
static::deleted(fn () => self::removeCached());
|
|
}
|
|
|
|
// * RELATIONS
|
|
|
|
/**
|
|
* Theme relation
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
*/
|
|
public function theme(): BelongsTo
|
|
{
|
|
return $this->belongsTo(FaqTheme::class, 'theme_id');
|
|
}
|
|
}
|