skip to Main Content

I’m building a booking system in Laravel, look at below image
enter image description here

Today is 3, my customers booked in current month 1,6,8,10,12 and 25. I want to send a notification to those who left 6 days from today.

I want to send a notification to customers booked on 6 and 8 only and tomorrow I’ll send notification to 10 as well.

I tried

   public function test(){
      $orders = Order::whereDate('booked_at','>=',Carbon::now()->addDays(6))->get();

      return $orders;
    }

the above code return all the future booking not only 6 days from today.

any suggestion appreciated.

3

Answers


  1. you can try something like this

        public function test()
        {
            $orders = Order::wheredate('booked_at', '=', Carbon::now())
            ->orWhereDate('booked_at', '<', Carbon::now()->addDays(6))
                ->get();
    
            return $orders;
        }
    
    Login or Signup to reply.
  2. I suggest this, to easy changes the daysLeft on the next time you want to changes.

    public function test()
    {
       $daysLeft = 6;
       return Order::whereDate('booked_at', '>=', Carbon::now()->addDays($daysLeft))->get();
    }
    
    Login or Signup to reply.
  3. You are using >= to compare booked_at which will give you all orders that are booked at 6 days or more from now.

    If you want all orders booked exactly 6 days from now you can use:

     public function test(){
          $orders = Order::whereDate('booked_at','=',Carbon::now()->addDays(6))->get();
    
          return $orders;
        }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search