Skip to content

Commit

Permalink
- fix load eloquent collection relations in queued job
Browse files Browse the repository at this point in the history
  • Loading branch information
mtracz committed Jun 4, 2024
1 parent f27fe74 commit 2b21d26
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public function handle(VacationTypeConfigRetriever $configRetriever): void

foreach ($users as $user) {
$vacationRequests = VacationRequest::query()
->with(["user"])
->states(VacationRequestStatesRetriever::waitingForUserActionStates($user))
->get();

Expand Down
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 2b21d26

Please sign in to comment.