app/Http/Controllers/LessonController.php
/**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
Display a listing of the resource.
@return \Illuminate\Http\Response
Display a listing of the resource . @return \ Illuminate \ Http \ Response
public function index(Request $request)
    {
        $lessons = Lesson::query();
        $chapter_id = $request->query('chapter_id');
        $lessons->when($chapter_id, function ($query, $chapter_id) {
            return $query->where('chapter_id', $chapter_id);
        });
        return response()->json([
            "status" => "success",
            "data" => $lessons->get()
        ]);
    }
public function index ( Request $ request ) { $ lessons = Lesson :: query ( ) ; $ chapter_id = $ request -> query ( 'chapter_id' ) ; $ lessons -> when ( $ chapter_id , function ( $ query , $ chapter_id ) { return $ query -> where ( 'chapter_id' , $ chapter_id ) ; } ) ; return response ( ) -> json ( [ " status " => " success " , " data " => $ lessons -> get ( ) ] ) ; }
Display a listing of the resource.
Display a listing of the resource .