Laravel Eloquent Query导致Application连续加载

I wrote the following eloquent query for a table in my application and now the application won't stop loading. what i need is to understand what is wrong with it and how to fix it

    $customer_purchased_1_time=DB::table("data as t1")->select('vin','last_service')
              ->where('type',1)->distinct('vin')
              ->whereRaw("(select count(*) from data where t1.vin=data.vin and data.type=1)=1")
              ->count();

It is the only code in my controller method along with the return statement. the incrementing of x was for debugging

I solved it already. and this code worked fine for me

$customer_purchased_1_time=count(DB::table("data as t1")
              ->select('vin','last_service',DB::raw("count(*) as count"))
              ->where('type',1)
              ->distinct('vin')
              ->having("count","=",1)
              ->get());