GroupController.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace App\Http\Controllers\Admin\Syj;
  3. use App\Models\Syj\GroupModel;
  4. use Illuminate\Http\Request;
  5. use App\Http\Controllers\Controller;
  6. class GroupController extends Controller
  7. {
  8. //
  9. public function index()
  10. {
  11. $groups = GroupModel::get();
  12. return response([
  13. 'code' => 200,
  14. 'message' => 'OK',
  15. 'data' => $groups
  16. ]);
  17. }
  18. public function store(Request $request)
  19. {
  20. $this->validate($request, [
  21. 'name' => 'required',
  22. 'image' => 'required',
  23. 'capacity_number' => 'required|integer',
  24. 'total_number' => 'integer|integer',
  25. 'expired_at' => 'required|integer',
  26. 'state' => 'integer',
  27. ]);
  28. $group = GroupModel::create($request->all());
  29. return response([
  30. 'code' => 200,
  31. 'message' => 'OK',
  32. 'data' => $group
  33. ]);
  34. }
  35. public function update(Request $request, $id)
  36. {
  37. $this->validate($request, [
  38. 'name' => '',
  39. 'image' => '',
  40. 'capacity_number' => 'integer',
  41. 'total_number' => 'integer',
  42. 'expired_at' => 'integer',
  43. 'state' => 'integer',
  44. ]);
  45. $group = GroupModel::findOrFail($id);
  46. $group->update($request->all());
  47. return response([
  48. 'code' => 200,
  49. 'message' => 'Success',
  50. 'data' => $group
  51. ]);
  52. }
  53. }