<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Course extends Model
{
    use HasFactory;

    protected $hidden = [
         'deleted_at'
    ];

    public function course_holes()
    {
        return $this->hasMany(CourseHole::class, 'course_id', 'id');
    }

    public function course_fileds()
    {
        return $this->hasMany(CourseField::class, 'course_id', 'id');
    }

    public function setOpeningHoursAttribute($opening_hours) {
        $this->attributes['opening_hours'] = trim(implode('~', $opening_hours));
    }

    public function setUpdatedAtAttribute($value)
    {
        $this->attributes['updated_at'] = date('Y-m-d H:i', strtotime($value));
    }
}
