Documentation

Team Review Notifications

AI Powered
Back to Docs

Advertisement

Team Review Notifications

Documentation & Guides

Team Review Notifications

Overview

The team review notification system automatically notifies teams when a scrim status changes from "Ongoing" to one of the following statuses:

  • Completed - The scrim has finished and stats are available
  • Waiting on Stats - The scrim has finished but stats are not yet available
  • Stats Missing - The scrim has finished but no stats were recorded

How It Works

1. Model Events

The Scrim model uses Laravel's model events to automatically detect when the status field changes from "ongoing" to target statuses.

2. Notification Trigger

When a status change is detected, the model's booted() method:

  • Checks if the status is changing from "ongoing" to target statuses
  • Calls the sendTeamReviewNotifications() method
  • Sends notifications to all teams in the scrim
  • Only sends notifications if the other team is on RiftSurge (has a team record)

3. Notification Delivery

Notifications are sent via:

  • Database - Stored in the notifications table for in-app display
  • Discord - Sent to the team's Discord channel if configured

Notification Content

Database Notification

[

'scrim_id' => $scrim->id,

'other_team_id' => $otherTeam->id,

'other_team_name' => $otherTeam->name,

'new_status' => 'completed',

'message' => "Your scrim vs Team Beta has completed. Please review the other team's performance.",

'view_url' => route('scrims.show', $scrim),

]

Discord Notification

  • Title: "Team Review Request"
  • Description: Customized message based on status
  • Color:
  • Green for "completed"
  • Orange for "waiting_on_stats"
  • Red for "no_stats"
  • Fields: Scrim details, status, and action required
  • Buttons: "View Scrim" and "Review Team" links

Files Created/Modified

New Files

  • app/Notifications/TeamReviewRequest.php - Notification class
  • tests/Feature/Notifications/TeamReviewNotificationTest.php - Notification tests
  • tests/Feature/Jobs/UpdateScrimAndGamesStatusWithNotificationsTest.php - Job tests

Modified Files

  • app/Models/Scrim.php - Added model event handling and notification method
  • app/Jobs/UpdateScrimAndGamesStatus.php - Simplified (removed event dispatching)

Implementation Details

Model Event Handling

protected static function booted()

{

static::updating(function ($scrim) {

if ($scrim->isDirty('status')) {

$oldStatus = $scrim->getOriginal('status');

$newStatus = $scrim->status->value;

if ($oldStatus === ScrimStatus::ONGOING->value) {

$targetStatuses = ['completed', 'waiting_on_stats', 'no_stats'];

if (in_array($newStatus, $targetStatuses)) {

$scrim->sendTeamReviewNotifications($newStatus);

}

}

}

});

}

Notification Method

protected function sendTeamReviewNotifications(string $newStatus): void

{

foreach ($this->teams as $team) {

$otherTeam = $this->teams->where('id', '!=', $team->id)->first();

if ($otherTeam) {

$team->notify(new TeamReviewRequest($this, $team, $newStatus));

}

}

}

Testing

Run the tests to verify the notification system works correctly:

php artisan test --filter=TeamReviewNotificationTest

php artisan test --filter=UpdateScrimAndGamesStatusWithNotificationsTest

Configuration

The notification system is automatically enabled when:

1. Teams have Discord integration configured

2. Teams are participating in scrims

3. Scrim status changes from "ongoing" to target statuses

No additional configuration is required.

Advantages of Model Events

  • Simpler architecture - No need for custom events and listeners
  • Automatic triggering - Works with any code that updates the scrim status
  • Better encapsulation - Logic is contained within the model
  • Easier testing - Direct model updates trigger notifications
  • More reliable - No risk of forgetting to dispatch events
Need help? Check our FAQ

Advertisement