<?php

namespace Seka\Vzdelavanie\Models\Kniznica;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Elceka\Laravel\HashId\Http\Traits\Hashidable;

/**
 * Class Kategoria
 * @package Seka\Vzdelavanie\Models\Kniznica
 */
class Kategoria extends Model
{
    use Hashidable;
    use HasFactory;

    /**
     * @var string
     */
    protected $table = 'vzdelavanie_kniznica_kategorie';

    /**
     * @var array
     */
    protected $fillable = [
        'id',
        'nazov',
        'obrazok',
    ];

    /**
     *
     */
    protected static function boot()
    {
        parent::boot();

        static::deleting(function (Kategoria $kategoria) {
            $kategoria->ucebnice->each->delete();
        });
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function ucebnice()
    {
        return $this->hasMany(Ucebnica::class, 'kategoria_id', 'id');
    }

    /**
     * @param string      $childType
     * @param mixed       $value
     * @param string|null $field
     *
     * @return \Illuminate\Database\Eloquent\Model|void|null
     */
    public function resolveChildRouteBinding($childType, $value, $field)
    {
        // TODO: Implement resolveChildRouteBinding() method.
    }
}
