Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Presto's avatar

Passing Data To Queue Job Class

Hello,

Im trying to build my first queued job class and I'm needing to pass data to my job class from my controller that queued the job. Is this the correct way to do it?

Within my controller

$this->dispatch(new ProcessPhoto($id, $file_name));
...

Within my Job class

public function handle($id, $file_name)
...
0 likes
4 replies
bobbybouwmann's avatar

You can instantiate the variable you passed in the constructor

class ProcessPhoto extends Job implements SelfHandling, ShouldQueue
{
    use InteractsWithQueue;

    protected $id;

    protected $file_name;

    public function __construct($id, $file_name)
    {
        $this->id = $id;
        $this->file_name = $file_name;
    }

    public function handle()
    {
        // $this->id;
        // $this->file_name;
    }
}

Documentation: http://laravel.com/docs/5.1/queues#writing-job-classes

5 likes
Presto's avatar

Thank you so much for your help @bobbybouwmann, hey do we have to do anything within the handler to release the job from the queue once it is complete or let the queue know its complete or will the queuing system just know its complete and remove it from the queue?

Thanks again @bobbybouwmann

Please or to participate in this conversation.