2
votes

I'm trying to get queues working in laravel 5 and the queue listener is outputting:

php artisan queue:listen

[ErrorException]
Undefined index: table

The "jobs" and "failed_jobs" tables are present, config.php is set to "database".

A search of the laravel forum and google has not yielded a solution, amy ideas where to look?

2
did you manage to find the solution? somewhat i am also having same issue edit: ok nvm, i forgot to update to QUEUE_DRIVER=databasesulaiman sudirman

2 Answers

0
votes

This is most likely not a fault of the Laravel Queue system. Instead, this error is thrown by PHP when an array is to be accessed by an unknown/unset element.

"Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset" using PHP

For example:

    // Initialise an empty array
    $myArray = [];

    // Attempt to access an element that hasn't been set yet
    echo $myArray['breadCake'];

In your case, have a look through your code that deals with queueing and search for ['table'], ["table"] or anything that would need a "table" set.

It may be handy to anyone reading this and considering using Laravel Queues to remember a few things:

  • Queues are asynchronous and do not have access to the variables you once set in the application unless you pass them into something queue-able.

  • In Laravel 5, capture all the data you require for a job to exist in the Event __construct() method. Events have access to a trait called SerializesModels. You can pass your models as instances (with attributes) to the __construct() method (such as __construct(User $user). Assign your variables to the Event class scope (for example: $this->user = $user). This is passed to the EventListener handle(Event $event) method. This is called when the queue is being processed. The __construct() should be blank (or filled in with repositories / services / other handy bits and pieces).

  • You can access the objects passed to the handle(Event $event) method:

    public function handle(MyEvent $myEvent) 
    {
        $this->user = $myEvent->user;
        $mailData = ['user'=>$this->user];
        Mail::queue('viewdir.view',$mailData, function($message) use ($mailData) {
            $message->to($mailData['user']->email);
            // other stuff
        });
    }
    

I hope this helps anyone reading.

0
votes

So I had the same problem but I discovered that I had set my driver to sync while using the database as the sync driver. setting my driver as database solved it for me