$steps * @property User|null $user * @property int|null $user_id * * @method static Builder pending() * @method static ReportFactory factory(...$parameters) */ class Report extends BaseModel { use HasFactory; final public const TABLE = 'reports'; final public const ATTRIBUTE_ID = 'report_id'; final public const ATTRIBUTE_FINISHED_AT = 'finished_at'; final public const ATTRIBUTE_MODERATOR = 'moderator_id'; final public const ATTRIBUTE_MOD_NOTES = 'mod_notes'; final public const ATTRIBUTE_NOTES = 'notes'; final public const ATTRIBUTE_STATUS = 'status'; final public const ATTRIBUTE_USER = 'user_id'; final public const RELATION_MODERATOR = 'moderator'; final public const RELATION_STEPS = 'steps'; final public const RELATION_USER = 'user'; /** * Is auditing disabled? * * @var bool */ public static $auditingDisabled = true; /** * The attributes that are mass assignable. * * @var list */ protected $fillable = [ Report::ATTRIBUTE_FINISHED_AT, Report::ATTRIBUTE_MODERATOR, Report::ATTRIBUTE_MOD_NOTES, Report::ATTRIBUTE_NOTES, Report::ATTRIBUTE_STATUS, Report::ATTRIBUTE_USER, ]; /** * The table associated with the model. * * @var string */ protected $table = Report::TABLE; /** * The primary key associated with the table. * * @var string */ protected $primaryKey = Report::ATTRIBUTE_ID; public function getName(): string { return strval($this->getKey()); } public function getSubtitle(): string { if ($user = $this->user) { return $user->getName(); } return strval($this->getKey()); } /** * Get the attributes that should be cast. * * @return array */ protected function casts(): array { return [ Report::ATTRIBUTE_FINISHED_AT => 'datetime', Report::ATTRIBUTE_STATUS => ApprovableStatus::class, ]; } /** * Scope a query to only include pending reports. * * @param Builder $query */ #[Scope] public function pending(Builder $query): void { $query->where(Report::ATTRIBUTE_STATUS, ApprovableStatus::PENDING->value); } /** * @return HasMany */ public function steps(): HasMany { return $this->hasMany(ReportStep::class, ReportStep::ATTRIBUTE_REPORT); } /** * Get the moderator that is working on the report. * * @return BelongsTo */ public function moderator(): BelongsTo { return $this->belongsTo(User::class, Report::ATTRIBUTE_MODERATOR); } /** * Get the user that made the report. * * @return BelongsTo */ public function user(): BelongsTo { return $this->belongsTo(User::class, Report::ATTRIBUTE_USER); } }