59 lines
1.2 KiB
PHP
59 lines
1.2 KiB
PHP
<?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\HasMany;
|
|
|
|
class Communication extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $fillable = [
|
|
'user_id',
|
|
'order_id',
|
|
'name',
|
|
'email',
|
|
'phone',
|
|
'subject',
|
|
'message',
|
|
'status',
|
|
'admin_notes',
|
|
'ip_address',
|
|
'user_agent',
|
|
'last_replied_at',
|
|
];
|
|
|
|
protected $casts = [
|
|
'last_replied_at' => 'datetime',
|
|
];
|
|
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
public function order(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Order::class);
|
|
}
|
|
|
|
public function replies(): HasMany
|
|
{
|
|
return $this->hasMany(CommunicationReply::class)->oldest();
|
|
}
|
|
|
|
public function getStatusLabelAttribute(): string
|
|
{
|
|
return match ($this->status) {
|
|
'new' => 'Nieuw',
|
|
'in_progress' => 'In behandeling',
|
|
'resolved' => 'Beantwoord',
|
|
'closed' => 'Gesloten',
|
|
default => ucfirst($this->status),
|
|
};
|
|
}
|
|
}
|