| xqd
@@ -2,6 +2,7 @@
|
|
|
|
|
|
namespace App\Admin\Controllers;
|
|
|
|
|
|
+use App\Models\Product;
|
|
|
use App\Models\ProductCategory;
|
|
|
use Dcat\Admin\Form;
|
|
|
use Dcat\Admin\Grid;
|
| xqd
@@ -10,6 +11,22 @@ use Dcat\Admin\Http\Controllers\AdminController;
|
|
|
|
|
|
class ProductCategoryController extends AdminController
|
|
|
{
|
|
|
+
|
|
|
+ public function destroy($id)
|
|
|
+ {
|
|
|
+ $childIds = ProductCategory::where('pid',$id)->get()->pluck('id');
|
|
|
+ $childIds[]= $id;
|
|
|
+
|
|
|
+ $hasEpisode = Product::whereIn('cate_id',$childIds)->count();
|
|
|
+ if($hasEpisode){
|
|
|
+ $form = new Form();
|
|
|
+ $response = $form->response();
|
|
|
+ return $response->error('当前分类或子分类存在产品,前先删除产品后再删除分类');
|
|
|
+ }
|
|
|
+
|
|
|
+ return $this->form()->destroy($id);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Make a grid builder.
|
|
|
*
|