为什么值一直是 null
TestPsy 与 TestReply 关系如下
TestPsy.php
public function testreplies()
{
return $this->hasMany(TestReply::class);
}
TestReply.php
public function testpsy()
{
return $this->belongsTo(TestPsy::class);
}
数据可以成功提交到数据库里,但是用
Observer
处理的时候,$testreply->testpsy
这个是null,导致报错
TestReplyObserver.php
public function created(TestReply $testreply)
{
$testreply->testpsy->reply_count = $testreply->testpsy->testreplies->count();
$testreply->testpsy->save();
}
我想问问,
$testreply->testpsy
里的testpsy
是不是就是models里的TestPsy?这个dd出来应该是一个完整的数组才对,但是现在是null
在 tinker 中,
$testreply->testpsy
拿出来有值吗?