activityRepository = new ActivityRepository; } /** * Display a listing of the resource. */ public function index(Request $request) { $perPage = $request->has('per-page') ? $request->input('per-page') : null; $filter = $request->has('filter') ? $request->input('filter') : []; $activities = $this->activityRepository->allActivities($perPage, $filter); return view('activity::index', compact('activities')); } /** * Show the form for creating a new resource. */ public function create() { return view('activity::create'); } /** * Store a newly created resource in storage. */ public function store(CreateActivityRequest $request): RedirectResponse { try { $validated = $request->validated(); $this->activityRepository->storeActivity($validated); toastr()->success('Activity created successfully.'); return redirect()->route('cms.activities.index'); } catch (\Throwable $th) { report($th); toastr()->error('Something went wrong.'); return back(); } } /** * Show the specified resource. */ public function show($id) { return view('activity::show'); } /** * Show the form for editing the specified resource. */ public function edit($uuid) { $activity = $this->activityRepository->findActivityByUuid($uuid); if (!$activity) { toastr()->error('Activity not found.'); return back(); } return view('activity::edit', compact('activity')); } /** * Update the specified resource in storage. */ public function update(CreateActivityRequest $request, $uuid): RedirectResponse { try { $validated = $request->validated(); $activity = $this->activityRepository->updateActivity(validated: $validated, uuid: $uuid); if (!$activity) { toastr()->error('Banner not found !'); return back(); } toastr()->success('Activity updated successfully.'); return redirect()->route('cms.activities.index'); } catch (\Throwable $th) { report($th); toastr()->error('Something went wrong.'); return back(); } } /** * Remove the specified resource from storage. */ public function destroy($uuid) { try { $activity = $this->activityRepository->deleteActivity(uuid: $uuid); if (!$activity) { toastr()->error('Activity not found.'); return back(); } toastr()->success('Activity deleted successfully.'); return redirect()->route('cms.activities.index'); } catch (\Throwable $th) { report($th); toastr()->error('Something went wrong.'); return back(); } } }