beyondcode / beyondcode/laravel-mailbox

Queue getQueuableId issue

Open
#17 6 comments 1 reaction 0 assignees View on GitHub
Dominant language
PHP
Stars
1.1k
Forks
127
PR merge metrics
No merged PRs in 30d

Description

Thanks for this package.

I was running into this exception

```
BeyondCode\Mailbox\InboundEmail::id must return a relationship instance.
[stacktrace]
#0 vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php(397): Illuminate\\Database\\Eloquent\\Model->getRelationshipFromMethod('id')
#1 vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php(327): Illuminate\\Database\\Eloquent\\Model->getRelationValue('id')
#2 vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(1388): Illuminate\\Database\\Eloquent\\Model->getAttribute('id')
#3 vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(1398): Illuminate\\Database\\Eloquent\\Model->getKey()
#4 vendor/laravel/framework/src/Illuminate/Queue/SerializesAndRestoresModelIdentifiers.php(32): Illuminate\\Database\\Eloquent\\Model->getQueueableId()
#5 vendor/laravel/framework/src/Illuminate/Queue/SerializesModels.php(23): App\\Jobs\\ProcessInboundEmail->getSerializedPropertyValue(Object(BeyondCode\\Mailbox\\InboundEmail))
```

When running

```php
Mailbox::catchAll(function (InboundEmail $email) {
dispatch(new ProcessInboundEmail($email));
});
```

I see this is because the email model is only saved at the end of any Mailbox routes, so there is no id to serialize for queued jobs.

I can fix this by updating the queued job to the following, but wanted to check if you'd accept a PR to match Mailbox routes first then call storeEmail before running any routes?

```php
Mailbox::catchAll(function (InboundEmail $email) {
$email->save();
dispatch(new ProcessInboundEmail($email));
});
```

Thanks :)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.