skip to Main Content

I want to get daily data from my database. I try 2 code and both are not working for me.

$sales=Sale::whereDate('created_at', '=', Carbon::today());

The error that I got:

Class ‘AppHttpControllersCarbon’ not found

and when I try

$sales=Sale::whereDay('created_at', now()->day)->get();

The error that I got:

Call to undefined function AppHttpControllersnow()

3

Answers


  1. put use CarbonCarbon; at top after namespace then use this code.

    $sales=Sale::whereDate('created_at', Carbon::today())->get();
    
    Login or Signup to reply.
  2. You should try to import Carbon and then use it:

    use CarbonCarbon;
    

    Then inside your code you can use Carbon like:

    Carbon::now();
    
    Carbon::today();
    
    Login or Signup to reply.
  3. here in laravel created_at returns a value with Y-m-d & time & minute with all of this information

    $now=Carbon::now();
    here how returns the value with Y-m-d & time & minute with all of this information.&it changing every second.

    Now here if you want to get your query then need to format your getting now or today.try this,

    use CarbonCarbon;
    
    $now_date=Carbon::today()->fomat('Y-m-d');
    $sales=Sale::whereDate('created_at', '=',$now_date);
    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search