MadMaks
6 months ago

How can i refactor this queries to get the number of specific Users

Posted 6 months ago by MadMaks

Hey, is there a better way to refactor this queries? The way i did it is working but i don't think it is very smart. Any ideas?

//counts
        $PremiumUser = User::whereHas("roles", function($q){ $q->where("name", "Premium-Subscriber"); })->count();
        $Subscriber = User::whereHas("roles", function($q){ $q->where("name", "Subscriber"); })->count();
        $NewUser = User::whereDate('created_at','>=', date('Y-m-d H:is',strtotime('-7 days')))->count();


        return view('users.index', compact('users', 'PremiumUser' , 'Subscriber' , 'NewUser'));

Thanks in advance :)

Please sign in or create an account to participate in this conversation.