在 Laravel 作业类中,其代码如下图所示。如果满足条件,我想为我的对象分配一个属性(保留不是数据库上的列)。问题是我在构造函数之外看不到该属性。请问我做错了什么?
class SomeJob implements ShouldQueue
{
private $length = 300;
private $width;
private $area;
public function __construct()
{
$areas = Area::where('length', $this->length)->get()->each(function($area) {
if($area->length === 300) {
$area->reserve = ($area->length + 400);
}
});
$this->area = $areas;
// *log has $area
}
public function handle()
{
$area = $this->area;
logger($area);
// *log does not have $area
}
}
慕沐林林
慕标5832272
慕哥9229398
桃花长相依