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
You are using the
now()
function that produces a timestamp.I believe you need to pass a date (or Carbon) object:
Make sure that there are records in your database that meet the criteria specified in your
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.
Hope this will help you