StationRuleBatchController.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Components\AsyncResponse;
  4. use App\Http\Requests\Station\StationRuleBatchRequest;
  5. use App\Services\OwnerService;
  6. use App\StationRuleBatch;
  7. use Illuminate\Contracts\Foundation\Application;
  8. use Illuminate\Contracts\View\Factory;
  9. use Illuminate\Http\Request;
  10. use Illuminate\Http\Response;
  11. use Illuminate\Support\Facades\Gate;
  12. use Illuminate\View\View;
  13. class StationRuleBatchController extends Controller
  14. {
  15. use AsyncResponse;
  16. /**
  17. * Display a listing of the resource.
  18. *
  19. * @param Request $request
  20. * @param OwnerService $ownerService
  21. * @return Application|Factory|View
  22. */
  23. public function index(Request $request,OwnerService $ownerService)
  24. {
  25. if(!Gate::allows('站管理-站规则')){ return redirect(url('/')); }
  26. $stationRuleBatches = StationRuleBatch::query()->with('stationType','owner')->orderByDesc('id')->paginate($request['paginate'] ?? 50);
  27. $owners = $ownerService->getAuthorizedOwners();
  28. return view('station.rule.index',compact('stationRuleBatches','owners'));
  29. }
  30. /**
  31. * store API
  32. * @param StationRuleBatchRequest $request
  33. */
  34. public function storeApi(StationRuleBatchRequest $request)
  35. {
  36. $this->gate('站管理-站规则-编辑');
  37. $stationRuleBatch = StationRuleBatch::query()->create($request->only(['name','owner_id']));
  38. $stationRuleBatch->load('stationType','owner');
  39. $this->success($stationRuleBatch);
  40. }
  41. /**
  42. * update API
  43. * @param StationRuleBatchRequest $request
  44. */
  45. public function updateApi(StationRuleBatchRequest $request)
  46. {
  47. $this->gate('站管理-站规则-编辑');
  48. $stationRuleBatch = StationRuleBatch::query()->whereKey($request['id'])->first();
  49. $stationRuleBatch->update($request->all());
  50. $stationRuleBatch->load('stationType','owner');
  51. $this->success($stationRuleBatch);
  52. }
  53. public function destroyApi(Request $request)
  54. {
  55. $this->gate('站管理-站规则-删除');
  56. StationRuleBatch::query()->whereKey($request['id'])->delete();
  57. $this->success();
  58. }
  59. /**
  60. * Show the form for creating a new resource.
  61. *
  62. * @return Response
  63. */
  64. public function create()
  65. {
  66. //
  67. }
  68. /**
  69. * Store a newly created resource in storage.
  70. *
  71. * @param \Illuminate\Http\Request $request
  72. * @return Response
  73. */
  74. public function store(Request $request)
  75. {
  76. //
  77. }
  78. /**
  79. * Display the specified resource.
  80. *
  81. * @param \App\StationRuleBatch $stationRuleBatch
  82. * @return Response
  83. */
  84. public function show(StationRuleBatch $stationRuleBatch)
  85. {
  86. //
  87. }
  88. /**
  89. * Show the form for editing the specified resource.
  90. *
  91. * @param \App\StationRuleBatch $stationRuleBatch
  92. * @return Response
  93. */
  94. public function edit(StationRuleBatch $stationRuleBatch)
  95. {
  96. //
  97. }
  98. /**
  99. * Update the specified resource in storage.
  100. *
  101. * @param \Illuminate\Http\Request $request
  102. * @param \App\StationRuleBatch $stationRuleBatch
  103. * @return Response
  104. */
  105. public function update(Request $request, StationRuleBatch $stationRuleBatch)
  106. {
  107. //
  108. }
  109. /**
  110. * Remove the specified resource from storage.
  111. *
  112. * @param \App\StationRuleBatch $stationRuleBatch
  113. * @return Response
  114. */
  115. public function destroy(StationRuleBatch $stationRuleBatch)
  116. {
  117. //
  118. }
  119. }