UserAuth.php 1.5 KB

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