UserCourse.php 1.8 KB

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