отношения один-ко-многим в laravel не спасают

У меня есть отношения один ко многим между таблицей уведомлений и таблицей alertFrequency. Все модели работают нормально, единственное, чего не хватает, это следующее.
отметка времени в таблице alertFrequency для определенных веб-сайтов, записанных в таблице уведомлений, используется для расчета времени прохождения, а затем определения, отправлять ли уведомление или нет, а также вставлять новую запись в таблицу alertfrequency. У меня есть класс контроллера, называемый контроллером жрет. функция с именем add предназначена для этого, но потерпела неудачу, но у меня есть функция с именем addToNotification, она присоединяет значения к сводной таблице и работает нормально. я был бы признателен за предложения и помощь?

private function addStatusToNotification(Notification $notification, Status $status, $resCode)    {
$notification->statuses()->attach($status, [
'values' => strval($resCode)
]);
}

/*function to add new time stamp into the alertFrequency table*/
private function add(Notification $notification, AlertFrequency $alertTime){
$notification->alertFrequencies()->save($alertTime);
}

private function sendNotification(Notification $notification, $status_health, $alert_frequency, $resCode,$alertTime, AlertFrequency $alert)    {
// If this is the first time we check, OR if the status changed from up to down and vice versa, notify!!!
if (empty($status_health['timestamp']) || Notification::health($resCode) <> Notification::health($status_health['value'])){
$this->report($notification,$resCode);
return;
}
// If the website is (still) down and the alert frequency is exceeded, notify!!!
if(Notification::health($resCode) === 'down' && \Carbon\Carbon::parse($alertTime)->diffInMinutes() >= $alert_frequency){
$this->report($notification,$resCode);
//expected to save the new record in the alertFrequencies table but failed to do so
$this->add($notification,$alert);
}
}

public function status()
{
$notifications = Notification::where('active', 1)->get();

$alert = AlertFrequency::with('notification')->first();

$status = Status::where('name', 'health')->first();

foreach ($notifications as $notification) {
$this->updateStatus($notification, $status,$alert);
}
}

private function updateStatus(Notification $notification, Status $status, AlertFrequency $alert)
{
$status_health = $notification->status('health');
$check = empty($status_health['timestamp']);
$elapsed_time = $check ? 10000 : \Carbon\Carbon::parse($status_health['timestamp'])->diffInMinutes();

$check_frequency = $this->getCheckFrequency($notification);
/* create an attachemtn in to the alerFrequenct table*/
$alertTime = $notification->getLastTimestampAttribute();

if ($check || $elapsed_time >= $check_frequency) {
$resCode = $this->getStatusCode($notification->website_url);
$this->addStatusToNotification($notification, $status, $resCode);
$this->sendNotification(
$notification,
$status_health,
$this->getAlertFrequency($notification),
$resCode,
$alertTime,
$alert
);
}
}

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector