I have a one to many relationship between notification and alerFrequencies table. they have models for both. I wrote this function to extract all the latest created_at
time stamp from the alerFrequencies table.
Example, if I have one website in my notification table with created_at
time stamps in the alert table, it should return me the latest time stamp only. If I have 2 websites in the notification table with a different time stamp, it should return the time stamp for the 2 websites apart.
Here it returns only the latest regardless of the number of websites in the notification table. ony one who get a better idea to write the query, i would appreciate all kinds of help and suggestions.
public function alert(){
$alert_timestamp = AlertFrequency::with('notification')->select('created_at')->groupBy('created_at')->orderBy('created_at','DESC')->first();
$alert_timestamp=$alert_timestamp->created_at->toDateTimeString();
if($alert_timestamp==null){
return false;
}
return $alert_timestamp;
}
in the database i have to tables notifications and alerFrequencies table, with one to many relationship. the notification_id is a foreign key in the alertFreqency table. notification has columns: is, website url and alertFrequencies has : id. notification_id and created_at. now i want to get the latest created_at for every website in the notification table.