<?php

namespace App\Models;

use Dcat\Admin\Traits\HasDateTimeFormatter;

use Dcat\Admin\Traits\ModelTree;
use Illuminate\Database\Eloquent\Model;
use Spatie\EloquentSortable\Sortable;

class BaseProductCategory extends Model
{
    use HasDateTimeFormatter,
        ModelTree {
        ModelTree::boot as treeBoot;
    }

    //名称
    protected $titleColumn = 'name';
    //排序
    protected $orderColumn = 'order';
    //父级
    protected $parentColumn = 'parent_id';

    protected $table = 'base_product_category';

    protected $casts = [
        'created_at' => 'datetime:Y-m-d H:i:s',
        'updated_at' => 'datetime:Y-m-d H:i:s',
    ];

    protected $fillable = [
        'name', 'parent_id', 'order','enabled','parameter_id', // 假设已有的可填充字段
    ];

    /*
     * 关联产品参数
     */
    public function baseProductParameter()
    {
        return $this->hasOne(BaseProductParameter::class,'id','parameter_id');
    }


//    public static function selectOptions(\Closure $closure = null)
//    {
//        $options = (new static())->withQuery($closure)->buildSelectOptions();
//        return collect($options)->all();
//    }
}
