I am using Laravel 5.5 to create a simple queue that will resize an uploaded image. I cannot figure out how to pass parameters to the queue, such as the temporary file location of the image. My colleagues have used older versions of Laravel where a string could be passed to a job eg:
$this->dispatch(new ExampleJob($foo));
However, in Laravel 5.5 passing a string in the same way, eg:
ExampleJob::dispatch($foo);
will trigger a 'BindingResolutionException' exception as it's expecting a model to serialize.
If that's the case, how do I pass anything else in?
Something Like this works for me in Laravel 5.7 and Laravel 5.5...
ExampleJob::dispatch($foo);
Then the class and constructor look like this...
<?php
class ExampleJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $foo;
public function __construct($foo)
{
$this->foo = $foo;
}
public function handle()
{
$bar = $this->foo;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With