Category: Models & ORM

Q: Cakephp find data that was created one month ago

I am working on an API service for creating financial reports. Now I want to limit the application: 

  1. Not to create a new report if there was already an existing report that created in the past one month (like today - created_date < 30 days)
  2. I want a Cakephp find statement that can find an existing or no report.

Can someone help?

1 Answers

Version: 3

Use the exists function to check record's existence.

if ($reports->exists(['created >= ' => $date_one_month_ago_from_today]))
    //do something
} else
    //create a new financial report