UsersInfoForm.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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\Http\Controllers\AdminController;
  7. use Dcat\Admin\Traits\LazyWidget;
  8. use Dcat\Admin\Form;
  9. use PHPUnit\Util\Exception;
  10. class UsersInfoForm extends AdminController
  11. {
  12. use LazyWidget;
  13. private $model;
  14. public function __construct($data = '', $key = null)
  15. {
  16. parent::__construct($data, $key);
  17. //dd($data);
  18. $this->model = $data;
  19. }
  20. public function handle(array $input)
  21. {
  22. $user = User::query()->find($input['id']);
  23. if(!$user){
  24. return $this->response()->error('请刷新后重试');
  25. }
  26. if($input['mobile']!=$user->mobile && User::query()->where('mobile',$input['mobile'])->first()){
  27. return $this->response()->error('该手机号码已被使用');
  28. }else{
  29. $user->mobile = $input['mobile'];
  30. }
  31. if($input['password']!=''){
  32. $user->password = $input['password'];
  33. }
  34. $user->save();
  35. return $this->response()->success('保存成功')->refresh();
  36. }
  37. public function form()
  38. {
  39. $form = new Form($this->model);
  40. //$user_info = UserInfoModel::query()->where('user_id',$this->payload['id'])->first();
  41. //dd($this->model());
  42. $form->text('user_id');//->value($this->payload['id'])->readOnly();
  43. $form->text('nickname', '昵称');//->value($user_info->nickname);
  44. $form->image('avatar', '头像');//->url($user_info->avatar);
  45. }
  46. }