skip to Main Content

this is my code in my controller:

public function getPublicPost($school_id){
    $public_feeds = app(AllyFeedRepository::class)->query()
    ->whereHas('user_detail', function($q){
        $q->whereNull('deleted_at');
    })
    ->with('user_detail:id,name,profile_photo_path,deleted_at','userInstance:id,user_id,role_id','userInstance.role:id,name','announcement:id,description,file_path,type,deleted_at')
    ->whereSchoolId($school_id)
    ->orWhere('school_id' ,'=', null)
    ->orderBy('created_at','DESC')
    ->paginate(15);
    return $public_feeds;
}

then I add ->whereDate(‘deadline_viewing’, ‘>=’, now()) in my query suddenly I can’t fetch the data

public function getPublicPost($school_id){
    $public_feeds = app(AllyFeedRepository::class)->query()
    ->whereHas('user_detail', function($q){
        $q->whereNull('deleted_at');
    })
    ->with('user_detail:id,name,profile_photo_path,deleted_at','userInstance:id,user_id,role_id','userInstance.role:id,name','announcement:id,description,file_path,type,deleted_at')
    ->whereSchoolId($school_id)
    ->orWhere('school_id' ,'=', null)
    ->whereDate('deadline_viewing', '>=', now())
    ->orderBy('created_at','DESC')
    ->paginate(15);
    return $public_feeds;
}

I’m expecting I can fetch the data with that query

2

Answers


  1. You are using the now() function that produces a timestamp.
    I believe you need to pass a date (or Carbon) object:

    ->whereDate('deadline_viewing', '>=', IlluminateSupportCarbon::now())
    
    Login or Signup to reply.
  2. Make sure that there are records in your database that meet the criteria specified in your

    whereDate clause (deadline_viewing >= now())
    

    You can use a tool like a database client or Laravel’s built-in tinker to inspect the data in your database table.

    You can enable the error log by adding the following code. with this, you will find the issue.

    DB::enableQueryLog(); // Enable query logging
    
    // Your query here
    
    // Log and display the queries
    dd(DB::getQueryLog());
    

    Hope this will help you

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search