在Lumen框架中设置队列

时间:2015-11-28 08:33:01

标签: laravel laravel-5.1 lumen laravel-queue

我正在尝试使用流明页面中的指南在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
{
    //
}

BaseController.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
     } 
}

我得到了

  

未定义的方法App \ Http \ Controllers \ BlastsController :: dispatch

我错过了什么吗?

1 个答案:

答案 0 :(得分:0)

查看代码,BlastsController扩展App\Http\Controllers\BaseController而非App\Http\Controllers\Controller

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

修改

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