UsersInfoForm.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace App\Admin\Actions\Users;
  3. use App\Models\User;
  4. use App\Models\UserInfoModel;
  5. use Dcat\Admin\Contracts\LazyRenderable;
  6. use Dcat\Admin\Traits\LazyWidget;
  7. use Dcat\Admin\Widgets\Form;
  8. use PHPUnit\Util\Exception;
  9. class UsersInfoForm extends Form implements LazyRenderable
  10. {
  11. use LazyWidget;
  12. public function __construct($data = [], $key = null)
  13. {
  14. parent::__construct($data, $key);
  15. dd($this->payload['user_id']);
  16. }
  17. public function handle(array $input)
  18. {
  19. $user_info = UserInfoModel::query()->find($input['user_id']);
  20. if(!$user_info){
  21. return $this->response()->error('请刷新后重试');
  22. }
  23. $user_info->update($input);
  24. return $this->response()->success('保存成功')->refresh();
  25. }
  26. public function form()
  27. {
  28. $user_info = UserInfoModel::query()->where('user_id',$this->payload['user_id'])->first();
  29. $this->fill($user_info);
  30. $this->text('user_id',"用户ID")->readOnly();
  31. $this->text('nickname', '昵称')->required();
  32. $this->image('avatar', '头像')->disk('oss')->saveFullUrl()->uniqueName()->removable(false);
  33. $this->text('weixin', '微信号');
  34. $this->text('birthday', '生日');
  35. $this->text('height', '身高');
  36. $this->text('weight', '体重');
  37. $this->text('work', '职业');
  38. $this->text('info', '个人简介');
  39. $this->text('area', '所在地区')->default("成都市");
  40. $this->text('figure', '身材');
  41. $this->text('feeling', '感情状态');
  42. $this->text('education', '学历');
  43. $this->text('income', '年收入');
  44. $this->text('hobby', '兴趣爱好')->help("多个字段用,隔开,例如:唱歌,跳舞");
  45. $this->text('drink', '喝酒');
  46. $this->text('smoke', '抽烟');
  47. $this->array('photo', function (Form $form) {
  48. $form->image('url','图片')->disk('oss')->saveFullUrl()->uniqueName()->removable(false);
  49. $form->radio('state','阅后即焚')->options([0=>"否",1=>"是"])->default(0);
  50. })->saveAsJson()->label('相册');
  51. //$this->file('video', '视频')->saveAsJson();
  52. }
  53. }