maki1234's avatar

Event doesn't work.

I an trying add simple test event into my application, but it doesn't work...

route:

$app->get('/test/{id}', 'TestController@show');

controller

<?php

namespace App\Http\Controllers;

use Event;
use App\Events\TestEvent;
use Laravel\Lumen\Routing\Controller as BaseController;

class TestController extends BaseController {
    public function show($id) {
        Event::fire(new TestEvent($id));
   }
}

TestEvent

<?php

namespace App\Events;

use Illuminate\Queue\SerializesModels;

class TestEvent extends Event {
    use SerializesModels;

    public $id;

    public function __construct($id) {
        $this->id = $id;
    }
}

TestListener

<?php

namespace App\Listeners;

use App\Events\TestEvent;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;

class TestListener {

        public function __construct()
    {
        //
    }
    public function handle(TestEvent $event) {
        echo $event->id;
    }
}

EventServiceProvider

<?php

namespace App\Providers;

use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;

class EventServiceProvider extends ServiceProvider
{
    /**
     * The event listener mappings for the application.
     *
     * @var array
     */
    protected $listen = [
        'App\Events\TestEvent' => [
            'App\Listeners\TestListener',
        ],
    ];
}

I want to simply show id parameter...

0 likes
0 replies

Please or to participate in this conversation.