Ad

Using Subquery In Laravel To Find Count Of A Product Type In Same Tables With Multiple Where Conditions?

- 1 answer

My question may not be clear, if you cannot understand please mention.

This is the complete structure of the table

enter image description here

Issue

  1. Get count of all applications for the user
  2. Remove first five applications from the select and get remaining count of it.
  3. In the above output's count need to filter type of product and get count for each product type.

Code Tried

$res_applications_count = CreateApplicationModel::where('rs_users_id', $sub_user_id)
    //->skip($skip)
    ->take($limit)
    ->where([
        ['application_status', '!=', 'Not Submitted'], 
        ['application_status', '!=', 'InProgress']
    ])
    ->whereBetween('created', [$sub_start_date, $sub_end_date])
    ->where('product_type', '=', "Residential")
    ->orderBy('created', 'DESC')
    ->get()
    ->count();

Need to get different product types count after discounting the allowed limit from overall count of the user's application. for ex 5 counts to be removed from 100 applications and check remaining 95 for product types.

Expected Ans

Total count - 100 Discount - 5 Remaining- 95

In Remaining get count of different types:

First type - 50 Second type - 20 Third Smooth - 25

Ad

Answer

Not sure if it is what you are looking for, but here is the user's applications count by product_type and skipping first $skip numbers of results:

$applications_count_by_product_type = CreateApplicationModel::where('rs_users_id', $sub_user_id)
    ->skip($skip)
    ->groupBy('product_type')
    ->count();
Ad
source: stackoverflow.com
Ad