<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class ChaosEvents extends Model
{
    protected $table = 'chaos_events';

    protected function casts(): array
    {
        return [
            'from_date_internal' => 'date',
            'to_date_internal' => 'date',
            'from_date_visible' => 'date',
            'to_date_visible' => 'date',
        ];
    }

    public function preApplications() {
        return $this->hasMany('App\Models\PreApplications', 'event_id');
    }

    public static function getActiveEvents(){
        return self::where('to_date_internal', '>=', today())
            ->where('from_date_internal', '<=', today())->get();
    }
}
