diff --git a/src/Notifynder/Models/Notification.php b/src/Notifynder/Models/Notification.php index b08e72c..380ca3c 100644 --- a/src/Notifynder/Models/Notification.php +++ b/src/Notifynder/Models/Notification.php @@ -53,6 +53,7 @@ class Notification extends Model 'extra' => 'array', ]; + protected $notifiedModelInstance; /** * Notification constructor. * @@ -72,6 +73,10 @@ public function __construct($attributes = []) } parent::__construct($attributes); + + + $notifiedModel= notifynder_config()->getNotifiedModel(); + $this->notifiedModelInstance = new $notifiedModel; } /** @@ -87,11 +92,13 @@ public function category() */ public function from() { + + if (notifynder_config()->isPolymorphic()) { return $this->morphTo('from'); } - return $this->belongsTo(notifynder_config()->getNotifiedModel(), 'from_id'); + return $this->belongsTo(notifynder_config()->getNotifiedModel(), 'from_id', $this->notifiedModelInstance->getKeyName()); } /** @@ -103,7 +110,7 @@ public function to() return $this->morphTo('to'); } - return $this->belongsTo(notifynder_config()->getNotifiedModel(), 'to_id'); + return $this->belongsTo(notifynder_config()->getNotifiedModel(), 'to_id', $this->notifiedModelInstance->getKeyName()); } /**