public function store(Request $request) { $filter = ['semester_id' => $this->semester->id, 'student_id' => $this->student->id, 'subject_id' => $request->input('subject_id')]; $recording = QuranRecording::firstOrCreate($filter); $extend = QuranTimeExtend::where($filter)->first(); if ($extend) { $extend->decrement('maximum_recordings'); } $videos = empty($recording->videos) ? [] : unserialize($recording->videos); if (!empty($recording->quran_video)) { array_push($videos, $recording->quran_video); } $recording->videos = serialize($videos); $recording->quran_video = $request->input('quran_video'); $recording->page = $request->input('page'); $recording->save(); $recording->load('grade'); $recording->decrement('remaining'); // $recording->remaining = $recording->remaining - 1; $recording->excuse = OrderQuranExcuse::where(['semester_id' => semester()->id, 'student_id' => $recording->student_id, 'subject_id' => $recording->subject_id])->first(); return response()->json($recording, 200, [], JSON_NUMERIC_CHECK); }
/** * Display a listing of the resource. * @return Response */ public function index() { $extends = QuranTimeExtend::where('student_id', $this->student->id)->select('maximum_recordings', 'start_at', 'finish_at', 'subject_id')->where('semester_id', $this->semester->id)->get(); return response()->json($extends, 200, [], JSON_NUMERIC_CHECK); }
/** * Show the form for editing the specified resource. * @return Response */ public function edit($id = 0) { $time_extend = QuranTimeExtend::with('subject')->findOrFail($id); return view('quran::edit', compact('time_extend')); }