<?php

namespace App\Admin\Repositories;

use App\Models\BaseProduct as Model;
use Dcat\Admin\Form;
use Dcat\Admin\Repositories\EloquentRepository;

class BaseProduct extends EloquentRepository
{
    /**
     * Model.
     *
     * @var string
     */
    protected $eloquentClass = Model::class;

    /*
     * 重写删除方法
     */
    public function delete(Form $form, array $originalData)
    {
        collect(explode(',', $form->getKey()))->filter()->each(function ($id) {
            Model::find($id)->images()->delete();//把图片也删了
            Model::find($id)->delete();
        });
        return true;
    }
}
