Get data on daily or monthly limit?

  • 0
    Good evening, guys, please help me for 4 hours. I've been puzzling, I can't do it.

    There are several products in the database, and they have a purchase restriction,
    Daily limit: 100 pcs.
    Monthly limit: 1000 pcs.

    If one product exceeds the limit of more than 100 or 1000, then the product with a different id is displayed from the base, but the characteristics are the same.

    $count = 1000 ;
            $daily = Carbon::now()->startOfDay();
            $month = Carbon::now()->subDays(30)->startOfDay();
            $q = Shop::where('id','=',1)
                    ['limit_day','<=', $count ],
                    ['created_at', '<=',  $daily],
                    ['limit_month', '<=', $count ],
                    ['created_at', '>=',  $month]

    Doesn't help.

    Help yes guys really need your help, please!
    MySQL Anonymous, Nov 23, 2020

  • 1 Answers
  • 0
    And that limit_day and limit_month go to zero every day / month?

    You need to keep logs of purchases separately, then it will be possible to calculate the number of purchases today and the number of purchases per month

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!