54 lines
1.5 KiB
PHP
54 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace Peidikeji\Goods\Http\Admin;
|
|
|
|
use Dcat\Admin\Form;
|
|
use Dcat\Admin\Grid;
|
|
use Dcat\Admin\Http\Controllers\AdminController;
|
|
use Peidikeji\Goods\Models\Goods;
|
|
use Peidikeji\Goods\Models\GoodsBrand;
|
|
|
|
class GoodsBrandController extends AdminController
|
|
{
|
|
protected $translation = 'dcat-admin-goods::goods-brand';
|
|
|
|
protected function grid()
|
|
{
|
|
return Grid::make(new GoodsBrand(), function (Grid $grid) {
|
|
$grid->disableRowSelector();
|
|
|
|
$grid->disableViewButton();
|
|
|
|
$grid->column('name');
|
|
$grid->column('image')->image('', 120);
|
|
});
|
|
}
|
|
|
|
protected function form()
|
|
{
|
|
return Form::make(new GoodsBrand(), function (Form $form) {
|
|
$form->text('name');
|
|
$form->image('image')
|
|
->autoUpload()
|
|
->saveFullUrl()
|
|
->move('goods/brand');
|
|
|
|
$form->disableResetButton();
|
|
$form->disableCreatingCheck();
|
|
$form->disableViewCheck();
|
|
$form->disableEditingCheck();
|
|
|
|
$form->deleting(function (Form $form) {
|
|
$data = $form->model()->toArray();
|
|
foreach ($data as $item) {
|
|
$id = data_get($item, 'id');
|
|
// 品牌下面包含商品, 阻止删除
|
|
if (Goods::where('brand_id', $id)->exists()) {
|
|
return $form->response()->error('请先删除关联的商品');
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|