UsersInfoForm.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. }
  16. public function handle(array $input)
  17. {
  18. $user_info = UserInfoModel::query()->find($input['user_id']);
  19. if(!$user_info){
  20. return $this->response()->error('请刷新后重试');
  21. }
  22. $user_info->update($input);
  23. return $this->response()->success('保存成功')->refresh();
  24. }
  25. public function form()
  26. {
  27. if(request()->ajax()){
  28. $user_info = UserInfoModel::query()->where('user_id',$this->payload['user_id'])->first();
  29. $this->fill($user_info);
  30. }
  31. // else{
  32. // dd(222222);
  33. // }
  34. // $user_info = UserInfoModel::query()->where('user_id',$this->payload['user_id'])->first();
  35. // $this->fill($user_info);
  36. $this->text('user_id',"用户ID")->readOnly();
  37. $this->text('nickname', '昵称')->required();
  38. $this->image('avatar', '头像')->disk('oss')->saveFullUrl()->uniqueName()->removable(false);
  39. $this->text('weixin', '微信号');
  40. $this->text('birthday', '生日');
  41. $this->text('height', '身高');
  42. $this->text('weight', '体重');
  43. $this->text('work', '职业');
  44. $this->text('info', '个人简介');
  45. $this->text('area', '所在地区')->default("成都市");
  46. $this->text('figure', '身材');
  47. $this->text('feeling', '感情状态');
  48. $this->text('education', '学历');
  49. $this->text('income', '年收入');
  50. $this->text('hobby', '兴趣爱好')->help("多个字段用,隔开,例如:唱歌,跳舞");
  51. $this->text('drink', '喝酒');
  52. $this->text('smoke', '抽烟');
  53. $this->array('photo', function (Form $form) {
  54. $form->image('url','图片')->saveFullUrl()->uniqueName()->removable(false);
  55. $form->radio('state','阅后即焚')->options([0=>"否",1=>"是"])->default(0);
  56. })->saveAsJson()->label('相册');
  57. //$this->file('video', '视频')->saveAsJson();
  58. }
  59. }