1

I try to override method of vendor class:

namespace App\Providers\Rewritten;

use Illuminate\Queue\DatabaseQueue;

class MyDatabaseQueue extends DatabaseQueue
{

    protected function buildDatabaseRecord($queue, $payload, $availableAt, $attempts = 0)
    {
        //my code here
    }
}

And i try to register alias in AppServiceProvider like this:

$loader = AliasLoader::getInstance();

$loader->alias(
            'Illuminate\Queue\DatabaseQueue',
            'App\Providers\Rewritten\MyDatabaseQueue'
        );

And then i have error myssage:

Class 'Illuminate\Queue\DatabaseQueue' not found

But why? I don't understand. Can sombody help with that?

Buboon
  • 405
  • 5
  • 15

2 Answers2

0

Your arguments to the alias() method are in the wrong order. Instead of:

$loader->alias(
    'Illuminate\Queue\DatabaseQueue',
    'App\Providers\Rewritten\MyDatabaseQueue'
);

You need to switch them:

$loader->alias(
    'App\Providers\Rewritten\MyDatabaseQueue',
    'Illuminate\Queue\DatabaseQueue'
);

The first argument is your class, and the second argument is the alias, which means that the old class name will be an alias to your new class.

Perry Holden
  • 116
  • 3
  • Good catch, if true. I'd suggest providing a link to documentation or API reference where this is stated. – miken32 Nov 22 '19 at 23:35
-1

try adding use Illuminate\Queue\DatabaseQueue; in AppServiceProvider.php

Haseeb Zulfiqar
  • 316
  • 3
  • 11