Replies: 1 comment
-
Can't you just pass the config into the constructor? class InvoicePaidListener implements ShouldQueue
{
public function __construct(
private string $connection,
private int $invoiceId,
) {}
public function handle()
{
Invoice::on($this->connection)->find($this->invoiceId);
// or DB::connection($this->connection) …
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm building quite a big app at the moment and I encountered an issue regarding my listeners and jobs.
My idea is to add a property to every job class that specifies which method should be called like so:
The why:
I'm building a multi tenant application that uses multiple databases, which I've made work using the changing the database config mid-execution in my application, which has worked wonders. The problem arises whenever I dispatch an event or a job to be executed. I managed to make it so it dispatches the job on the correct queue e.g.:
If the current database is
shop_center
the job is executed on the queueshop_center
;shop_country
-->shop_country
.But the problem is whenever I send an Entity to that job, it serializes it, stores it in redis and after a while the queue worker picks it up.
If I've sent an entity coming from the database
shop_center
the queue worker does not know that and just uses the default databse which I've configured on start of the application. So the issue becomes that Laravel is trying to update an Entity in the database that may or may not exist based on if there is an id matching it.I've already implemented a fix that's about 5 lines of code inside of a single File, but in my vendor directory - which quite frankly scares me.
I'm talking about the
illuminate/events
library - file:vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php:536
Code:
Now I know that my code may not look beautiful to some, I'm totally okay with changing it but it works for me. I'm wondering if a merge request would be accepted if I made one.
Every idea or criticism is welcome, and I'm looking for feedback!
Beta Was this translation helpful? Give feedback.
All reactions