<?php

namespace App\Models;

use Dcat\Admin\Traits\HasDateTimeFormatter;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Model;


/**
 * App\Models\ProductSpec
 *
 * @property int $id
 * @property int $product_id 产品ID
 * @property string $name 名称
 * @property int $sort 排序越大越靠前
 * @property int $is_opened 上架状态 0-下架 1-上架
 * @property string|null $specs 规格详情
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property \Illuminate\Support\Carbon|null $deleted_at
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property-read \App\Models\ProductSpecGroup|null $group
 * @method static \Illuminate\Database\Eloquent\Builder|ProductSpec newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|ProductSpec newQuery()
 * @method static \Illuminate\Database\Query\Builder|ProductSpec onlyTrashed()
 * @method static \Illuminate\Database\Eloquent\Builder|ProductSpec query()
 * @method static \Illuminate\Database\Eloquent\Builder|ProductSpec whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ProductSpec whereDeletedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ProductSpec whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ProductSpec whereIsOpened($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ProductSpec whereName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ProductSpec whereProductId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ProductSpec whereSort($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ProductSpec whereSpecs($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ProductSpec whereUpdatedAt($value)
 * @method static \Illuminate\Database\Query\Builder|ProductSpec withTrashed()
 * @method static \Illuminate\Database\Query\Builder|ProductSpec withoutTrashed()
 * @mixin \Eloquent
 * @property-read \App\Models\Product|null $product
 */
class ProductSpec extends Model
{
	use HasDateTimeFormatter;
    use SoftDeletes;

    protected $table = 'product_specs';

    protected $fillable = [
        'product_id',
        'name',
        'sale_price',
        'sort',
        'is_opened',
        'specs'
    ];

    protected $casts = [
        'specs' => 'json'
    ];

    public function product(): BelongsTo
    {
        return $this->belongsTo(Product::class,'product_id','id');
    }

}
