설명 없음

SectionController.php 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Professor;
  4. use App\Section;
  5. use Illuminate\Http\Request;
  6. use Illuminate\Support\Facades\DB;
  7. use Illuminate\Support\Facades\Log;
  8. class SectionController extends Controller
  9. {
  10. /**
  11. * Display a listing of the resource.
  12. *
  13. * @return \Illuminate\Http\Response
  14. */
  15. public function index()
  16. {
  17. //
  18. }
  19. /**
  20. * Show the form for creating a new resource.
  21. *
  22. * @return \Illuminate\Http\Response
  23. */
  24. public function create()
  25. {
  26. //
  27. }
  28. /**
  29. * Store a newly created resource in storage.
  30. *
  31. * @param \Illuminate\Http\Request $request
  32. * @return \Illuminate\Http\Response
  33. */
  34. public function store(Request $request)
  35. {
  36. $request = $request->validate([
  37. 'course_id' => ['required', 'integer', 'exists:courses,id'],
  38. 'semester_code' => ['required', 'size:3', 'exists:semesters,code'],
  39. 'section_count' => ['required', 'integer', 'max:50'],
  40. ]);
  41. for ($i=1; $i <= $request->section_count; $i++) {
  42. Section::create([
  43. 'course_id' => $request->course_id,
  44. 'semester_code' => $request->semester_code,
  45. 'code' => str_pad($i, 3, '0', STR_PAD_LEFT)
  46. ]);
  47. }
  48. return redirect('/course');
  49. }
  50. /**
  51. * Display the specified resource.
  52. *
  53. * @param \App\Section $section
  54. * @return \Illuminate\Http\Response
  55. */
  56. public function show(Section $section)
  57. {
  58. //
  59. }
  60. /**
  61. * Show the form for editing the specified resource.
  62. *
  63. * @param \App\Section $section
  64. * @return \Illuminate\Http\Response
  65. */
  66. public function edit(Section $section)
  67. {
  68. //
  69. }
  70. /**
  71. * Update the specified resource in storage.
  72. *
  73. * @param \Illuminate\Http\Request $request
  74. * @param \App\Section $section
  75. * @return \Illuminate\Http\Response
  76. */
  77. public function update(Request $request, Section $section)
  78. {
  79. // dd($request);
  80. $data = array_filter($request->validate([
  81. 'code' => ['nullable', 'size:3', 'string'],
  82. 'professor_id' => ['nullable', 'array'],
  83. 'professor_id.*' => ['exists:professors,id'],
  84. 'syllabus' => ['nullable', 'file', 'mimes:pdf'],
  85. 'credits' => ['nullable', 'numeric'],
  86. 'student_count' => ['nullable', 'integer'],
  87. ]));
  88. // TODO: Insert syllabus
  89. $section->update($data);
  90. foreach($data['professor_id'] as $professor_id) {
  91. $section->professors()->attach($professor_id);
  92. }
  93. // return 1;
  94. // return $request;
  95. // return next($request);
  96. return redirect()->back();
  97. }
  98. /**
  99. * Remove the specified resource from storage.
  100. *
  101. * @param \App\Section $section
  102. * @return \Illuminate\Http\Response
  103. */
  104. public function destroy(Section $section)
  105. {
  106. //
  107. }
  108. }