UsersInfoForm.php 1.5 KB

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