UserAuth.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace App\Admin\Actions\Users;
  3. use Dcat\Admin\Grid\RowAction;
  4. use Dcat\Admin\Widgets\Modal;
  5. use Illuminate\Http\Request;
  6. class UserAuth extends RowAction
  7. {
  8. protected $title = '<i class="feather icon-user-check"></i> 用户认证';
  9. protected $model;
  10. public function __construct(string $model = null)
  11. {
  12. $this->model = $model;
  13. }
  14. /**
  15. * 设置确认弹窗信息,如果返回空值,则不会弹出弹窗
  16. *
  17. * 允许返回字符串或数组类型
  18. *
  19. * @return array|string|void
  20. */
  21. public function confirm()
  22. {
  23. // return [
  24. // "确定认证吗?"
  25. // ];
  26. }
  27. /**
  28. * 处理请求
  29. *
  30. * @param Request $request
  31. *
  32. * @return \Dcat\Admin\Actions\Response
  33. */
  34. public function handle(Request $request)
  35. {
  36. // 获取当前行ID
  37. $id = $this->getKey();
  38. // 获取 parameters 方法传递的参数
  39. $model = $request->get('model');
  40. $apply = $model::find($id);
  41. $apply->is_auth=1;
  42. $apply->save();
  43. // 返回响应结果并刷新页面
  44. return $this->response()->success("操作成功")->refresh();
  45. }
  46. /**
  47. * 设置要POST到接口的数据
  48. *
  49. * @return array
  50. */
  51. public function parameters()
  52. {
  53. return [
  54. // 发送当前行 username 字段数据到接口
  55. 'status' => $this->row->is_auth,
  56. // 把模型类名传递到接口
  57. 'model' => $this->model,
  58. ];
  59. }
  60. public function render()
  61. {
  62. $form = UserAuthForm::make()->payload(['id'=>$this->getKey()]);
  63. return Modal::make()
  64. ->lg()
  65. ->title($this->title)
  66. ->body($form)
  67. ->button($this->title);
  68. }
  69. }