Search code examples
phplaraveldatetimepicker

Ways to add one more day to the PHP code by modifying the existing code


    public function doctorToday(Request $request){
        $doctors = Appointment::with('doctor')->whereDate('date',date('Y-m-d'))->get();
        return $doctors;

May I know how to implement one more day to the code? I want to get the tommorow's date instead of today's.


Solution

  • I would suggest using Carbon instead of date().

    public function doctorToday(Request $request){
        $doctors = Appointment::with('doctor')->whereDate('date',Carbon::now()->addDay()->format('Y-m-d'))->get();
        return $doctors;
    

    don't forget to add the use statement at the start of the class:

    use Illuminate\Support\Carbon;