I'm still trying to fix the problem without success, any ideas?
Thank you!
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi there!
I'm experiencing what I call an X-file... I am creating an application for volleyball leagues and I have created a functionality to generate the days of a league based on the teams that are part of it and divided into two parts:
All code is inside League class.
public function generateMatchdays($start)
{
/* ... */
if ($teams[$home] !== null && $teams[$away] !== null) {
$matchday[] = [
'matchday' => $round + 1,
'local_team' => $teams[$home],
'visitor_team' => $teams[$away],
'date' => $date->format('Y-m-d 12:00:00'),
];
}
/* ... */
}
public function createGamesFromMatchdays($matchdays)
{
$games = [];
foreach ($matchdays as $index => $matchday) {
/* ... */
$game = Game::create([/* ... */]);
$games[] = $game;
/* ... */
}
$federation_responsible = $this->responsible;
self::sendLeagueMatchesCreatedMail($federation_responsible, true);
$unique_coaches = collect($games)->flatMap(function ($game) {
return [$game->localTeam->coach, $game->visitorTeam->coach];
})->unique();
foreach ($unique_coaches as $coach) {
self::sendLeagueMatchesCreatedMail($coach);
}
return $games;
}
Now comes the X-file:
✅ If the number of teams is even, everything is executed correctly and the mails are sent.
❌ If the number of devices is odd, I get an error message Call to a member function getQueueableRelations() on null but the matches are inserted correctly into the database, so the problem is in sending emails...
I would really appreciate some help here because I'm a bit stuck. Thank you very much!
public function generateMatchdays($start)
{
$teams = $this->teams;
$numTeams = count($teams);
if($numTeams < 2) {
throw new Exception('Matchdays cannot be generated with less than 2 teams');
}
// If the number of teams is odd, add a "bye"
if ($numTeams % 2 != 0) {
$teams[] = null;
$numTeams++;
}
$halfway = $numTeams - 1;
$matchdays = [];
$start_date = Carbon::parse($start);
$date = $start_date->is('saturday') ? $start_date : $start_date->next('saturday');
for ($round = 0; $round < $halfway; $round++) {
$matchday = [];
for ($i = 0; $i < $numTeams / 2; $i++) {
$home = ($round + $i) % ($numTeams - 1);
$away = ($numTeams - 1 - $i + $round) % ($numTeams - 1);
if ($i === 0) {
$away = $numTeams - 1;
}
if ($teams[$home] !== null && $teams[$away] !== null) {
$matchday[] = [
'matchday' => $round + 1,
'local_team' => $teams[$home],
'visitor_team' => $teams[$away],
'date' => $date->format('Y-m-d 12:00:00'),
];
}
}
$date = $date->addWeek();
$matchdays[] = $matchday;
}
// Generate return matches
$return_matches = array_map(function ($matchday) use ($halfway, $date) {
$match = array_map(function ($match) use ($halfway, $date) {
return [
'matchday' => $match['matchday'] + $halfway,
'local_team' => $match['visitor_team'],
'visitor_team' => $match['local_team'],
'date' => $date->format('Y-m-d 12:00:00'),
];
}, $matchday);
$date = $date->addWeek();
return $match;
}, $matchdays, array_keys($matchdays));
$all_matchdays = array_merge(...$matchdays, ...$return_matches);
return $all_matchdays;
}
public function createGamesFromMatchdays($matchdays)
{
$games = [];
foreach ($matchdays as $index => $matchday) {
if($index === 0) {
$this->update(['start' => $matchday['date']]);
}
if($index === count($matchdays) - 1) {
$this->update(['end' => $matchday['date']]);
}
$local_team = $matchday['local_team'];
$visitor_team = $matchday['visitor_team'];
// Skip "bye" games
if ($local_team === null || $visitor_team === null) {
continue;
}
$court = $matchday['local_team']->sedes()->first()->courts()->first();
$game = Game::create([
'league_id' => $this->id,
'division_id' => $this->division_id,
'club_id' => $court->sede->club_id,
'sede_id' => $court->sede_id,
'court_id' => $court->id,
'referee_id' => 1,
'local_team_id' => $local_team->id,
'visitor_team_id' => $visitor_team->id,
'date' => $matchday['date'],
'requested_date' => null,
'date_requested_by' => null,
'matchday' => $matchday['matchday'],
'start' => $matchday['date'],
'end' => null,
'winner_team_id' => null,
'loser_team_id' => null,
'status' => null,
]);
$games[] = $game;
Call::create([
'game_id' => $game->id,
'team_id' => $game->local_team_id,
'locked' => false,
]);
Call::create([
'game_id' => $game->id,
'team_id' => $game->visitor_team_id,
'locked' => false,
]);
Set::create([
'game_id' => $game->id,
]);
}
$federation_responsible = $this->responsible;
self::sendLeagueMatchesCreatedMail($federation_responsible, true);
$unique_coaches = collect($games)->flatMap(function ($game) {
return [$game->localTeam->coach, $game->visitorTeam->coach];
})->unique();
foreach ($unique_coaches as $coach) {
self::sendLeagueMatchesCreatedMail($coach);
}
return $games;
}
public function createMatchdaysGames($start)
{
$matchdays = $this->generateMatchdays($start);
return $this->createGamesFromMatchdays($matchdays);
}
protected function sendLeagueMatchesCreatedMail(User $user, bool $is_federation = false)
{
Mail::to($user)->send(new LeagueMatchdaysCreated($user, $this, $is_federation));
}
Please or to participate in this conversation.