diff --git a/app/Classes/General/Interfaces/Notifiable.php b/app/Classes/General/Interfaces/Notifiable.php index b97a08c7..e9d8f22d 100644 --- a/app/Classes/General/Interfaces/Notifiable.php +++ b/app/Classes/General/Interfaces/Notifiable.php @@ -3,13 +3,13 @@ namespace App\Classes\General\Interfaces; -use Illuminate\Database\Eloquent\Relations\MorphMany; +use Illuminate\Database\Eloquent\Relations\MorphTo; interface Notifiable { - public function subject(): morphMany; + public function subject(): MorphTo; - public function target(): morphMany; + public function target(): MorphTo; - public function causer(): morphMany; + public function causer(): MorphTo; } \ No newline at end of file diff --git a/app/Models/AbstractModel.php b/app/Models/AbstractModel.php index 7a7c9c06..f459750f 100644 --- a/app/Models/AbstractModel.php +++ b/app/Models/AbstractModel.php @@ -3,11 +3,39 @@ namespace App\Models; +use App\Classes\General\Interfaces\Notifiable; use Illuminate\Database\Eloquent\Model; use Spatie\Activitylog\Traits\LogsActivity; +use Illuminate\Database\Eloquent\Relations\MorphTo; -class AbstractModel extends Model +class AbstractModel extends Model implements Notifiable { use LogsActivity; protected static $logFillable = true; + + /** + * @return MorphTo + */ + public function subject(): MorphTo + { + return $this->MorphTo('subject'); + } + + /** + * @return MorphTo + */ + public function target(): MorphTo + { + return $this->MorphTo('target'); + } + + /** + * @return MorphTo + */ + public function causer(): MorphTo + { + return $this->MorphTo('causer'); + } + + } \ No newline at end of file diff --git a/app/Models/Order.php b/app/Models/Order.php index 955e6a4c..5011fd36 100644 --- a/app/Models/Order.php +++ b/app/Models/Order.php @@ -34,31 +34,6 @@ class Order extends AbstractModel implements Addressable, Packable, Remarkable, return $this->belongsTo(CompanyModule::class, 'company_module_id', 'id'); } - /** - * @return MorphMany - */ - public function subject(): morphMany - { - return $this->morphMany(Notification::class, 'subject_type'); - } - - /** - * @return MorphMany - */ - public function target(): morphMany - { - return $this->morphMany(Notification::class, 'target'); - } - - /** - * @return MorphMany - */ - public function causer(): morphMany - { - return $this->morphMany(Notification::class, 'causer'); - } - - /** * @return MorphMany */