4
0
Fork 0
master
panliang 2022-08-01 15:07:32 +08:00
parent 54bd8cc1a3
commit a08604bf82
2 changed files with 47 additions and 0 deletions

View File

@ -2,6 +2,7 @@
namespace Peidikeji\Goods\Http\Controllers\Admin;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Grid\Tools\Selector;
use Dcat\Admin\Http\Controllers\AdminController;
@ -80,4 +81,36 @@ class GoodsController extends AdminController
$show->field('updated_at')->as(fn($v) => $this->updated_at->format('Y-m-d H:i:s'));
return $show;
}
protected function form()
{
return Form::make(new Goods(), function (Form $form) {
$form->select('category_id')->options(GoodsCategory::selectOptions(null, false))->required();
$form->select('brand_id')->options(GoodsBrand::pluck('name', 'id'));
$form->select('type_id')->options(GoodsType::pluck('name', 'id'));
$form->text('name')->required();
$form->text('goods_sn');
$form->image('cover_image')
->autoUpload()
->saveFullUrl()
->move('goods')
->required();
$form->multipleImage('images')
->autoUpload()
->saveFullUrl()
->move('goods');
$form->multipleImage('content')
->autoUpload()
->saveFullUrl()
->move('goods');
$form->number('price')->min(0)->attribute('step', 0.01);
$form->switch('on_sale');
$form->disableResetButton();
$form->disableCreatingCheck();
$form->disableViewCheck();
$form->disableEditingCheck();
});
}
}

View File

@ -49,6 +49,20 @@ class GoodsCategory extends Model
});
}
public static function selectOptions(\Closure $closure = null, $rootText = null)
{
$options = (new static())->withQuery($closure)->buildSelectOptions();
$list = collect($options);
if ($rootText !== false) {
$rootText = $rootText ?: admin_trans_label('root');
$list->prepend($rootText, 0);
}
return $list->all();
}
public function parent()
{
return $this->belongsTo(self::class, 'parent_id');