Skip to content

Commit

Permalink
- fix lazy loading in VacationRequest model (#442)
Browse files Browse the repository at this point in the history
* - fix lazy loading in VacationRequest model

* - fix load eloquent collection relations in queued job
  • Loading branch information
mtracz authored Jun 10, 2024
1 parent 3c57c7b commit 19668c0
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion app/Notifications/VacationRequestsSummaryNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace Toby\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Support\Carbon;
use Illuminate\Support\Collection;
use Toby\Slack\Elements\SlackMessage;
use Toby\Slack\Elements\VacationRequestsAttachment;

Expand All @@ -29,13 +29,17 @@ public function via(): array

public function toSlack(): SlackMessage
{
$this->loadRelations();

return (new SlackMessage())
->text(__("Requests wait for your approval - status for day :date:", ["date" => $this->day->toDisplayString()]))
->withAttachment(new VacationRequestsAttachment($this->vacationRequests));
}

public function toMail(Notifiable $notifiable): MailMessage
{
$this->loadRelations();

$url = route(
"vacation.requests.indexForApprovers",
[
Expand Down Expand Up @@ -74,4 +78,9 @@ protected function buildMailMessage(Notifiable $notifiable, string $url): MailMe
return $message
->action(__("Go to requests"), $url);
}

protected function loadRelations(): void
{
$this->vacationRequests->load(["user"]);
}
}

0 comments on commit 19668c0

Please sign in to comment.