@nickywan123 the problem is that your purchases is a collection instance, and on a collection you don't have an orders function, you will either need to iterate over each Purchase and call the orders count on it, and then sum the result, or maybe make the query a bit better like this:
$purchases = Purchase::where('user_id', $user->id)->whereIn('purchase_status', $statuses)
->withCount('orders')->get();
now in the resulting collection you will have a new field called orders_count which will contain the total number of orders for each purchase, then
$purchases->sum('orders_count'); // should be 4
NOTE I don't like the magic numbers btw, 3001, 3002, 3003 you should better name them and put a constant in order for you or another developer in the team to know what is going on :)