| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
- namespace App\Models;
- use Illuminate\Database\Eloquent\Factories\HasFactory;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- use Illuminate\Database\Eloquent\Relations\BelongsToMany;
- class ChatMessage extends Model
- {
- use HasFactory;
- public const NOTIFICATION_NONE = 'none';
- public const NOTIFICATION_RESPONSIBLES = 'responsibles';
- public const NOTIFICATION_ALL = 'all';
- public const NOTIFICATION_USER = 'user';
- public const NOTIFICATION_TYPE_NAMES = [
- self::NOTIFICATION_NONE => 'Нет',
- self::NOTIFICATION_RESPONSIBLES => 'Админы, менеджер, бригадир',
- self::NOTIFICATION_ALL => 'Все',
- self::NOTIFICATION_USER => 'Конкретному пользователю',
- ];
- protected $fillable = [
- 'order_id',
- 'reclamation_id',
- 'user_id',
- 'target_user_id',
- 'notification_type',
- 'message',
- ];
- public function order(): BelongsTo
- {
- return $this->belongsTo(Order::class);
- }
- public function reclamation(): BelongsTo
- {
- return $this->belongsTo(Reclamation::class);
- }
- public function user(): BelongsTo
- {
- return $this->belongsTo(User::class);
- }
- public function targetUser(): BelongsTo
- {
- return $this->belongsTo(User::class, 'target_user_id');
- }
- public function notifiedUsers(): BelongsToMany
- {
- return $this->belongsToMany(User::class, 'chat_message_user');
- }
- public function files(): BelongsToMany
- {
- return $this->belongsToMany(File::class, 'chat_message_file')->withTimestamps();
- }
- }
|