UsersInfoForm.php 2.1 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. }
  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. $user_info = UserInfoModel::query()->where('user_id',$this->payload['user_id'])->first();
  28. $this->fill($user_info);
  29. $this->text('user_id',"用户ID")->readOnly();
  30. $this->text('nickname', '昵称')->required();
  31. $this->image('avatar', '头像')->saveFullUrl()->uniqueName()->removable(false);
  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('hobby', '兴趣爱好')->help("多个字段用,隔开,例如:唱歌,跳舞");
  45. $this->text('drink', '喝酒');
  46. $this->text('smoke', '抽烟');
  47. $this->array('photo', function ($form) {
  48. $form->image('url','图片');//->saveFullUrl()->uniqueName()->removable(false);
  49. $form->radio('state','阅后即焚')->options([0=>"否",1=>"是"])->default(0);
  50. })->saveAsJson()->label('相册');
  51. }
  52. }