| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- <?php
- namespace App\Models;
- use App\Enums\NotificationRecipientEnum;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- use Illuminate\Database\Eloquent\Relations\HasMany;
- use Illuminate\Database\Eloquent\SoftDeletes;
- class Notification extends Model
- {
- use SoftDeletes;
- protected $table = 'custom_notifications';
- protected $guarded = ['id'];
- protected function casts(): array
- {
- return [
- 'recipient' => NotificationRecipientEnum::class,
- 'recipient_position_id' => 'integer',
- 'recipient_sector_id' => 'integer',
- ];
- }
- public function createdBy(): BelongsTo
- {
- return $this->belongsTo(User::class, 'created_by');
- }
- public function sends(): HasMany
- {
- return $this->hasMany(NotificationSend::class);
- }
- public function media(): HasMany
- {
- return $this->hasMany(Media::class, 'source_id')->where('source', 'notification');
- }
- }
|