validated(); $perPage = $validatedData['per_page'] ?? 15; $page = $validatedData['page'] ?? 1; $section = Section::where('book_id', $validatedData['book_id'])->paginate($perPage, ['*'], 'page', $page); $section->getCollection()->transform(function ($section) { unset($section['book_id']); $section['is_locked'] = auth()->user()->isSubscriber() !== false ? false : Law::where('id', $section['law_id'])->first()?->is_locked; unset($section['law_id']); return $section; }); return $this->success($section->items(), 'Success'); } public function like(Section $section) { $userId = auth()->id(); $existingLike = LikeSection::query()->where('section_id', $section->id) ->where('user_id', $userId) ->first(); if ($existingLike) { $existingLike->delete(); return $this->success(null, 'Success', 'Section unliked successfully'); } LikeSection::create([ 'section_id' => $section->id, 'user_id' => $userId, ]); return $this->success(null, 'Success', 'Section liked successfully'); } }