UsersInfoForm.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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\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 = User::query()->find($input['id']);
  19. if(!$user){
  20. return $this->response()->error('请刷新后重试');
  21. }
  22. if($input['mobile']!=$user->mobile && User::query()->where('mobile',$input['mobile'])->first()){
  23. return $this->response()->error('该手机号码已被使用');
  24. }else{
  25. $user->mobile = $input['mobile'];
  26. }
  27. if($input['password']!=''){
  28. $user->password = $input['password'];
  29. }
  30. $user->save();
  31. return $this->response()->success('保存成功')->refresh();
  32. }
  33. public function form()
  34. {
  35. $user_info = UserInfoModel::query()->where('user_id',$this->payload['id'])->first();
  36. $this->model($user_info);
  37. $this->text('user_id')->value($this->payload['id'])->readOnly();
  38. $this->text('nickname', '昵称');
  39. $this->image('avatar', '头像');
  40. }
  41. }