关于 OrderPaid 中的这段代码,求解其中有什么不同之处呢?
教程是这样的:
class OrderPaid
{
use Dispatchable, InteractsWithSockets, SerializesModels;
protected $order;
public function __construct(Order $order)
{
$this->order = $order;
}
public function getOrder()
{
return $this->order;
}
}
记得之前有文章是像下面这么写的
class OrderPaid
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $order; // protected 改成 public
public function __construct(Order $order)
{
$this->order = $order;
}
// getOrder() 这个方法不要了
}
在 listener
中 可以通过 $event->order
能够获取到 order
请问这两种写法有什么区别呢?
推荐文章: