UsersInfoForm.php 2.2 KB

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