createToken($user->email)->plainTextToken; $banners = Banner::where('status', true)->latest()->take(config('custom.HOME_RECORD_LIMIT'))->get(); $categories = Category::where('status', true)->latest()->take(config('custom.HOME_RECORD_LIMIT'))->get(); $courses = $user->courses; $transactions = $user->transactions; $settings = Setting::first(); $data = collect([ 'student' => new UserResource($user), 'banners' => BannerResource::collection($banners), 'courseCategories' => CategoryResource::collection($categories), 'courses' => CourseResource::collection($courses), 'transactions' => TransactionResource::collection($transactions), 'settings' => new SettingResource($settings), 'token' => $token ]); $message = 'Data fetched successfully'; return $this->apiResponse(true, $message, $data); } catch (\Throwable $exception) { return $this->apiResponse(false, $exception->getMessage()); } } public function profileUpdate(Request $request) { $validator = Validator::make($request->all(), [ 'notification_id' => ['required'], ]); if ($validator->fails()) { return $this->apiResponse(false, $validator->errors()->first(), $validator->errors()); } try { $user = Auth::user(); $user->update([ 'notification_id' => $request->notification_id ]); $message = 'Profile updated successfully'; return $this->apiResponse(true, $message); } catch (\Throwable $exception) { return $this->apiResponse(false, $exception->getMessage()); } } public function courses() { try { $user = Auth::user(); $courses = Course::where('student_id', $user->id)->with('allTransactions')->latest()->paginate(config('custom.PAGINATION_SIZE')); $data = CourseResource::collection($courses)->response()->getData(true); $message = 'Data retrieved successfully'; return $this->apiResponse(true, $message, $data); } catch (\Throwable $exception) { return $this->apiResponse(false, $exception->getMessage()); } } public function games() { try { $games = Game::where('status', 1)->latest()->paginate(config('custom.PAGINATION_SIZE')); $data = GameResource::collection($games)->response()->getData(true); $message = 'Data retrieved successfully'; return $this->apiResponse(true, $message, $data); } catch (\Throwable $exception) { return $this->apiResponse(false, $exception->getMessage()); } } public function categories() { try { $categories = Category::where('status', true)->latest()->paginate(config('custom.PAGINATION_SIZE')); $data = CategoryResource::collection($categories)->response()->getData(true); $message = 'Data retrieved successfully'; return $this->apiResponse(true, $message, $data); } catch (\Throwable $exception) { return $this->apiResponse(false, $exception->getMessage()); } } public function transactions() { try { $user = Auth::user(); $transactions = Transaction::where('student_id', $user->id)->latest()->paginate(config('custom.PAGINATION_SIZE')); $data = TransactionResource::collection($transactions)->response()->getData(true); $message = 'Data retrieved successfully'; return $this->apiResponse(true, $message, $data); } catch (\Throwable $exception) { return $this->apiResponse(false, $exception->getMessage()); } } public function notifications() { try { $notifications = Notification::latest()->paginate(config('custom.PAGINATION_SIZE')); $data = NotificationResource::collection($notifications)->response()->getData(true); $message = 'Data retrieved successfully'; return $this->apiResponse(true, $message, $data); } catch (\Throwable $exception) { return $this->apiResponse(false, $exception->getMessage()); } } public function videoCategories() { try { $videoCategories = VideoCategory::where('status', 1)->latest()->paginate(config('custom.PAGINATION_SIZE')); $data = VideoCategoryResource::collection($videoCategories)->response()->getData(true); $message = 'Data retrieved successfully'; return $this->apiResponse(true, $message, $data); } catch (\Throwable $exception) { return $this->apiResponse(false, $exception->getMessage()); } } public function randomVideos() { try { $randomVideos = Video::latest() ->whereHas('videoCategory', function ($query) { $query->where('status', 1); }) ->paginate(config('custom.PAGINATION_SIZE')); $data = VideoResource::collection($randomVideos)->response()->getData(true); $message = 'Data retrieved successfully'; return $this->apiResponse(true, $message, $data); } catch (\Throwable $exception) { return $this->apiResponse(false, $exception->getMessage()); } } public function categoryVideos($category_id) { try { $categoryVideos = Video::where('video_category_id', $category_id) ->whereHas('videoCategory', function ($query) { $query->where('status', 1); }) ->latest()->paginate(config('custom.PAGINATION_SIZE')); $data = VideoResource::collection($categoryVideos)->response()->getData(true); $message = 'Data retrieved successfully'; return $this->apiResponse(true, $message, $data); } catch (\Throwable $exception) { return $this->apiResponse(false, $exception->getMessage()); } } public function categoryNotes($category_id) { try { $categoryNotes = CategoryNotes::where('category_id', $category_id)->latest()->paginate(config('custom.PAGINATION_SIZE')); $data = CategoryNotesResource::collection($categoryNotes)->response()->getData(true); $message = 'Data retrieved successfully'; return $this->apiResponse(true, $message, $data); } catch (\Throwable $exception) { return $this->apiResponse(false, $exception->getMessage()); } } }