Notification.php 1019 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace App\Models;
  3. use App\Enums\NotificationRecipientEnum;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  6. use Illuminate\Database\Eloquent\Relations\HasMany;
  7. use Illuminate\Database\Eloquent\SoftDeletes;
  8. class Notification extends Model
  9. {
  10. use SoftDeletes;
  11. protected $table = 'custom_notifications';
  12. protected $guarded = ['id'];
  13. protected function casts(): array
  14. {
  15. return [
  16. 'recipient' => NotificationRecipientEnum::class,
  17. 'recipient_position_id' => 'integer',
  18. 'recipient_sector_id' => 'integer',
  19. ];
  20. }
  21. public function createdBy(): BelongsTo
  22. {
  23. return $this->belongsTo(User::class, 'created_by');
  24. }
  25. public function sends(): HasMany
  26. {
  27. return $this->hasMany(NotificationSend::class);
  28. }
  29. public function media(): HasMany
  30. {
  31. return $this->hasMany(Media::class, 'source_id')->where('source', 'notification');
  32. }
  33. }