因此,当在我正在处理的 laravel 5 应用程序中创建新订单时,我试图记录一些简单的事情。
所以我有一个OrderWasCreated
看起来像这样的事件:
<?php
namespace App\Events;
use App\Events\Event;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use App\Order;
class OrderWasCreated extends Event
{
use SerializesModels;
public $order;
/**
* OrderWasCreated constructor.
*/
public function __construct(Order $order)
{
$this->order = $order;
}
/**
* Get the channels the event should be broadcast on.
*
* @return array
*/
public function broadcastOn()
{
return [];
}
}
然后我OrderEventListener
看起来像这样:
<?php
namespace App\Listeners;
use App\Events\OrderWasCreated;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
class OrderEventListener
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
public function subscribe(Dispatcher $events)
{
$events->listen(
'App\Events\OrderWasCreated',
'App\Listeners\OrderEventListener@onOrderWasCreated'
);
}
/**
* Handle the event.
*
* @param OrderWasCreated $event
* @return void
*/
public function onOrderWasCreated(OrderWasCreated $event)
{
\Log::info('Order was created event fired');
}
}
在OrderController
我的商店方法中,我在某处有这个:
event(new OrderWasCreated($order));
然而,当我创建新订单时,我的日志文件中看不到任何内容。我错过了什么?