在 Lumen 框架中设置队列

Setting up Queue in Lumen Framework

我正在尝试使用 lumen 页面中的指南在 Lumen 中设置队列: http://lumen.laravel.com/docs/queues

<?php

namespace App\Jobs;

use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Bus\SelfHandling;
use Illuminate\Contracts\Queue\ShouldQueue;

class BlastEmail extends Job implements SelfHandling, ShouldQueue
{
    public function sendEmail()
    {
        [...CODE TO SEND EMAIL...]
    }

    public function handle()
    {
        $this->sendEmail();
    }
}

在我的控制器中

<?php

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use App\Jobs\BlastEmail;
use App\Models\Blast;
use App\Models\Subscriber;
use Illuminate\Http\Request;
use Validator;

class BlastsController extends BaseController
{
    public function queue(Request $request)
    {
        $job = (new BlastEmail($email,$request->input('content'),$request->input('title')));
        $this->dispatch($job);
    }
}

Controller.php

<?php

namespace App\Http\Controllers;
use Laravel\Lumen\Routing\Controller as BaseController;

class Controller extends BaseController
{
    //
}

基地Controller.php

use Dingo\Api\Routing\Helpers;
use Illuminate\Routing\Controller; 
use Cartalyst\Sentinel\Native\Facades\Sentinel;

class BaseController extends Controller {
     function someFunctionThatOtherGuyWrote()
     {
        // Some code that other guy wrote
     } 
}

我得到了

Undefined method App\Http\Controllers\BlastsController::dispatch

我是不是漏掉了什么?

查看您的代码,您的 BlastsController 扩展了 App\Http\Controllers\BaseController 而不是 App\Http\Controllers\Controller

您应该将其更改为扩展 Controlller class 将 class BlastsController extends BaseController 更改为 class BlastsController extends Controller 因为此 class 最终将使用 Laravel\Lumen\Routing\DispatchesJobs 特征包含 dispatch 方法

编辑

更新后你没有显示完整的 BaseController 文件,但你似乎扩展错误 class。您扩展 Illuminate\Routing\Controller,您应该扩展 App\Http\Controllers\Controller