Skip to content

Commit b939cb0

Browse files
committed
wip
1 parent 445da74 commit b939cb0

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/BaseNotification.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Eugenefvdm\NotificationSubscriptions\Models\NotificationTemplate;
77
use App\Models\User;
88
use Eugenefvdm\NotificationSubscriptions\Enums\RepeatFrequency;
9+
use Exception;
910
use Illuminate\Database\Eloquent\Model;
1011
use Illuminate\Notifications\Notification;
1112
use Illuminate\Support\Carbon;
@@ -123,7 +124,13 @@ public function getSubscriptionFromNotifiable(object $notifiable): ?Notification
123124
*/
124125
public static function getTemplate(): ?NotificationTemplate
125126
{
126-
return NotificationTemplate::where('notification_class', basename(static::class))->firstOrFail();
127+
$template = NotificationTemplate::where('notification_class', basename(static::class))->first();
128+
129+
if (!$template) {
130+
throw new Exception("Notification template not found for class: " . basename(static::class). ". Please ensure a notification has already been sent.");
131+
}
132+
133+
return $template;
127134
}
128135

129136
/**

src/Models/NotificationTemplate.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Illuminate\Database\Eloquent\Casts\Attribute;
77
use Illuminate\Database\Eloquent\Factories\HasFactory;
88
use Illuminate\Database\Eloquent\Model;
9-
use Illuminate\Database\Eloquent\Relations\BelongsTo;
109
use Illuminate\Database\Eloquent\Relations\HasMany;
1110

1211
class NotificationTemplate extends Model

0 commit comments

Comments
 (0)