0

I'm trying to set up queue in Lumen using the guide from lumen page: 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();
    }
}

and in My Controller

<?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
     } 
}

And I got

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

Do I miss something?

Yansen Tan
  • 551
  • 4
  • 19

1 Answers1

0

Looking at your code, your BlastsController extends App\Http\Controllers\BaseController and not App\Http\Controllers\Controller.

You should change it to extend Controlller class changing class BlastsController extends BaseController into class BlastsController extends Controller because this class will finally uses Laravel\Lumen\Routing\DispatchesJobs trait that contains dispatch method

EDIT

After update you didn't show full BaseController file but it seems you extends wrong class. You extend Illuminate\Routing\Controller and you should extend App\Http\Controllers\Controller

Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291
  • I got the "BaseController extends Controller" in BaseController.php. I believe it should be working right? – Yansen Tan Nov 28 '15 at 09:38
  • @YansenTan Please include then `BaseController.php` and `Controller.php` in your question – Marcin Nabiałek Nov 28 '15 at 09:42
  • I tried your suggestion and I got "Cannot use Laravel\Lumen\Routing\Controller as BaseController because the name is already in use in ... Controller.php". (I just update the question and add my BaseController.php and Controller.php). – Yansen Tan Nov 28 '15 at 09:50