I want to count users who have stripe_plan = platinum_monthly
$platinum=User::count('stripe_plan','platinum_monthly');
But its returning all users who have selected any available plan how to solve this issue need help?
In Laravel eloquent or query builder we use count method to count the rows. We can also count rows after executing the query using get() or all() and then can apply collection count method.
count is a Collection method. The query builder returns an array. So in order to get the count, you would just count it like you normally would with an array: $wordCount = count($wordlist); If you have a wordlist model, then you can use Eloquent to get a Collection and then use the Collection's count method.
$total = Model::sum('balance'); Note that it completely depends on your use case in the end.
Try adding the condition in a where clause
$platinum=User::where('stripe_plan','platinum_monthly')->count();
$platinum = User::where('stripe_plan', 'platinum_monthly')->count();
You have to select the users you want to count, not "count the users you want to count".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With