Report.php 1.6 KB

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