*/ use HasFactory; public const TYPE_AGB = 'agb'; public const TYPE_DATENSCHUTZ = 'datenschutz'; public const TYPE_RICHTLINIEN = 'richtlinien'; public const TYPE_MELDEVERFAHREN = 'meldeverfahren'; public const TYPE_IMPRESSUM = 'impressum'; protected $fillable = [ 'type', 'version', 'effective_from', 'note', ]; protected function casts(): array { return [ 'effective_from' => 'date', ]; } /** * Die heute gültige Fassung eines Rechtstexts (jüngstes effective_from * in der Vergangenheit; zukünftige Fassungen zählen noch nicht). */ public static function current(string $type): ?self { return static::query() ->where('type', $type) ->where('effective_from', '<=', today()) ->orderByDesc('effective_from') ->orderByDesc('id') ->first(); } /** * Versionsstring der gültigen AGB-Fassung — mit config/legal.php als * Fallback (Übergangslösung, bis der Seeder überall gelaufen ist). */ public static function currentAgbVersion(): string { return static::current(self::TYPE_AGB)?->version ?? (string) config('legal.agb_version'); } public function effectiveFromFormatted(): string { return Carbon::parse($this->effective_from)->locale('de')->isoFormat('D. MMMM YYYY'); } }