app/Http/Controllers/MyCourseController.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)
    {
        $myCourse = MyCourse::query()->with('course');
        $userId = $request->query('user_id');
        $myCourse->when($userId, function ($query, $userId) {
            return $query->where('user_id', $userId);
        });
        return response()->json([
            "status" => "success",
            "data" => $myCourse->get()
        ]);
    }
public function index ( Request $ request ) { $ myCourse = MyCourse :: query ( ) -> with ( 'course' ) ; $ userId = $ request -> query ( 'user_id' ) ; $ myCourse -> when ( $ userId , function ( $ query , $ userId ) { return $ query -> where ( 'user_id' , $ userId ) ; } ) ; return response ( ) -> json ( [ " status " => " success " , " data " => $ myCourse -> get ( ) ] ) ; }
Display a listing of the resource.
Display a listing of the resource .