Optimize laravel eloquent query

hello there i am working on a project with 30000 records, i want to print all the records on the paper, but when excute the following command,it keeps on loading the data until it runs out of memory, keep in mind i am fetching data with three different tables using relations with user_id in common in all the tables, i want to optimize the query, so that i can print all the user records seamlessly

$users= AppUser::with(['withdarawals','deposits'])->get()->groupBy('id');
        dd($users);