per_page) || is_null($request)) { $pagination = $request->per_page; } $shows = Show::searchFilter($request); if($request->has('showType')) { $showType = $request->get('showType'); $shows = ($showType == 'show') ? $shows->doesntHave('spotShow') : $shows->has('spotShow'); } return $shows->orderBy('name') ->paginate($pagination) ->toJson(); } /** * @throws \Exception */ public function store(Request $request) { try { $showData = $request->all(); $showDays = $showData['show_days']; $showDJs = $showData['show_djs']; $this->createShow($showData, $showDays, $showDJs); return response()->json([ 'status' => 'success', 'message' => 'Show saved successfully!' ]); } catch (Exception $e) { return response()->json(['message' => $e->getMessage()], 500); } } public function show(Request $request, $showId) { try { $show = Show::findOrFail($showId); if ($request->has('withDjs')) { $show->setAttribute( 'show_djs', $show->showDjs()->pluck('subjs_id')->toArray() ); } return response()->json($show); } catch (Exception $e) { return response()->json(['message' => 'Show not found ' . $e->getMessage()], 500); } } /** * @throws Throwable */ public function update(Request $request, int $showId) { try { DB::beginTransaction(); $showData = $request->all(); $showDJs = $showData['show_djs']; $this->updateShow($showData, $showId, $showDJs); DB::commit(); return response()->json([ 'status' => 'success', 'message' => 'Show saved successfully!' ]); } catch (\Exception $e) { DB::rollBack(); Log::error($e->getMessage()); return response()->json(['error' => 'Failed to update show'], 500); } catch (Throwable $e) { throw new Exception($e->getMessage()); } } /** * @throws Throwable */ public function destroy(Request $request, int $showId) { try { DB::beginTransaction(); Show::destroy($showId); DB::commit(); return response()->json(['message' => 'Shows deleted']); } catch (Exception $e) { DB::rollBack(); Log::error($e->getMessage()); return response()->json(['error' => 'Show not deleted'], 500); } catch (Throwable $e) { throw new Exception($e->getMessage()); } } }