<?php

namespace App\Models;

// use Carbon\Carbon;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;

class Chapter extends Model
{
    protected $fillable = [
        'title',
        'category_id',
        'course_id',
    ];

    // protected $with = ['category','course'];


    public function category()
    {
        return $this->belongsTo(Category::class);
    }

    public function course()
    {
        return $this->belongsTo(Course::class);
    }

    public function units()
    {
        return $this->hasMany(Unit::class);
    }

    public function lectures()
    {
        return $this->hasMany(Lecture::class);
    }

    public function getCreatedAtAttribute($date)
    {
        return \Carbon\Carbon::parse($date)->format('Y-m-d h:i A');
    }

    public function getUpdatedAtAttribute($date)
    {
        return Carbon::createFromTimestamp(strtotime($date))->format('Y-m-d h:i A');
    }
}
