<?php

namespace Seka\Vzdelavanie\Models\Kniznica;

use Core\Http\Traits\Hashidable;
use Illuminate\Database\Eloquent\Model;

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

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

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

    /**
     * @var string[]
     */
    protected $appends = [
        'hash_id',
    ];

    /**
     *
     */
    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.
    }
}
