framework icon indicating copy to clipboard operation
framework copied to clipboard

$deleteWhenMissingModels is being ignored for notifications

Open GalahadXVI opened this issue 1 week ago • 2 comments

Laravel Version

12.41.1

PHP Version

8.3

Database Driver & Version

No response

Description

I have a simple test that checks if a job fails silently when the model no longer exists. This test has been there for about a year without issue. Updated to Laravel 12 and its throwing ModelNotFoundException despite $deleteWhenMissingModels = true being enabled on the notification.

Not entirely sure if its intentional or not. $deleteWhenMissingModels isn't documented on the notification page. However, prior to Laravel 12, it worked.

Steps To Reproduce

This was the original test that was working in Laravel 11.

    # Create a character last action
    $last_action = UserLastAction::create([
        'user_id' => $last_action->id,
    ]);
    
    # Delete the character last action
    $last_action->delete();
    
    # Try to send the reminder with the deleted model
    $user->notify(new ActionReminder($last_action, Reminder::FIRST));
    
    # Assert no logs were created since the last action no longer exists
    assertCount(0, UserPushNotificationLog::all());

ActionReminder.php

class ActionReminder extends Notification implements ShouldQueue
{
    use Queueable;

    public $deleteWhenMissingModels = true;

    public function __construct(CharacterLastAction $user_last_action, Reminder $reminder)
    {
        $this->user_last_action = $user_last_action;
        $this->reminder = $reminder;
    }
...

Throwing:

Illuminate\Database\Eloquent\ModelNotFoundException: No query results for model [App\Models\UserLastAction].

Edit: Just to confirm, I rolled back to L11, changed $deleteWhenMissingModels to false, and it threw the error like expected. L12 seemingly ignored it completely.

GalahadXVI avatar Dec 05 '25 21:12 GalahadXVI