UsersInfoForm.php 1.4 KB

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