BatchEditProductForm.php 984 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace App\Admin\Actions\Form;
  3. use App\Models\Product;
  4. use Dcat\Admin\Contracts\LazyRenderable;
  5. use Dcat\Admin\Traits\LazyWidget;
  6. use Dcat\Admin\Widgets\Form;
  7. class BatchEditProductForm extends Form implements LazyRenderable
  8. {
  9. use LazyWidget;
  10. public function handle(array $input)
  11. {
  12. // 选择的行
  13. $ids = explode(',',$input['id']??null);
  14. if(empty($ids)){
  15. return $this->response()->error('参数错误');
  16. }
  17. foreach ($ids as $id){
  18. Product::where('id' , $id)->update([
  19. 'is_opened' => $input['is_opened'],
  20. ]);
  21. }
  22. return $this->response()->success('修改成功')->refresh();
  23. }
  24. public function form()
  25. {
  26. $this->radio('is_opened','是否上架')
  27. ->options(config('global.bool_status'))
  28. ->default(1);
  29. $this->hidden('id')->attribute('id','batch-id');
  30. }
  31. public function default()
  32. {
  33. }
  34. }