Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Notifynder/Collections/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ public function getNotifiedModel()
throw new InvalidArgumentException("The model class [{$class}] doesn't exist.");
}

/**
* @return string
*/
public function getNotifiedModelOwnerKey()
{
return (string) $this->get('model_owner_key', 'id');
}

/**
* @return array
*/
Expand Down
5 changes: 5 additions & 0 deletions src/Notifynder/Contracts/ConfigContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public function isTranslated();
*/
public function getNotifiedModel();

/**
* @return string
*/
public function getNotifiedModelOwnerKey();

/**
* @return array
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Notifynder/Models/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function from()
return $this->morphTo('from');
}

return $this->belongsTo(notifynder_config()->getNotifiedModel(), 'from_id');
return $this->belongsTo(notifynder_config()->getNotifiedModel(), 'from_id', notifynder_config()->getNotifiedModelOwnerKey());
}

/**
Expand All @@ -103,7 +103,7 @@ public function to()
return $this->morphTo('to');
}

return $this->belongsTo(notifynder_config()->getNotifiedModel(), 'to_id');
return $this->belongsTo(notifynder_config()->getNotifiedModel(), 'to_id', notifynder_config()->getNotifiedModelOwnerKey());
}

/**
Expand Down
7 changes: 7 additions & 0 deletions src/config/notifynder.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
*/
'model' => 'App\User',

/*
* If your model is not using id as it's primary key
* please specific it here, this option is not
* considerate if using notifynder as polymorphic
*/
'model_owner_key' => 'id',

/*
* Do you want have notifynder that work polymorphically?
* just swap the value to true and you will able to use it!
Expand Down