I have model review with:
public function shop()
{
return $this->belongsTo(Shop::class);
}
public function user()
{
return $this->belongsTo(User::class);
}
public function parent()
{
return $this->belongsTo(static::class, 'id', 'parent_id');
}
public function isParent()
{
return !$this->parent_id;
}
public function children()
{
return $this->hasMany(static::class, 'parent_id');
}
public function sendReviewNotification()
{
if ($this->isParent()) {
$this->shop->owner->sendReviewParentNotification($this);
} else {
if ($this->user->is($this->parent->user)) {
$this->shop->owner->sendReviewCommentNotification($this);
} else {
$this->parent->user->sendReviewCommentNotification($this);
}
}
}
When I add a child comment to a parrent comment I get error: 'Trying to get property 'user' of non-object', in ReviewObserver
I call sendReviewNotification like this:
public function created(Review $review)
{
$review->sendReviewNotification();
}
When I add parent module. Than all working, but when I add a child comment than I get this error. Why parent
relation not working?