Queue job, save model in $data array don't work as expected


I’m working with Queue job and I need to save a model to make some operations to it.

Fortunately, it seems that it’s quite easy with october as I can save a full model instance to my $data array and retrieve the full model instance in my Queue job as it’s said here :

If your queued job takes a model in its data, only the identifier for the model will be serialized onto the queue. When the job is actually handled, the queue system will automatically re-retrieve the full model instance from the database. It’s all totally transparent to your application and prevents issues that can arise from serializing full model instances.

Here is my code :

Queue::later(60, 'Me\MyModule\Classes\TextBulker@getText', ['model' => $this->model]);

Then, in my getText method :

public function getText($job, $data) {
    $data['model']->save(); // Call to a member function save() on array" on line 66 

I can notice that the “jobs” table in the database stock the whole serialized model, not just the ID to get it back later. And cannot retrieve the full model instance in my getText() method, it’s still an array and so, I cannot call any model methods.

What did I miss, can you provide me a working example ?

Thank you

Hey @PubliAlex

It looks like this statement is no longer valid in the documentation. We have created an internal task to review this documentation page.

For now, take a look at the Laravel 10 documentation, it should work as an alternative: Queues - Laravel - The PHP Framework For Web Artisans