I had problems making a sub query until I added the method ->toArray()
to the result, I hope it helps more than one since I had a good time looking for the solution.
Example
DB::table('user') ->select('id','name') ->whereNotIn('id', DB::table('curses')->select('id_user')->where('id_user', '=', $id)->get()->toArray()) ->get();