39 lines
776 B
PHP
39 lines
776 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Casts\NiceDate;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Carbon;
|
|
|
|
class Message extends Model
|
|
{
|
|
protected $casts = [
|
|
'created_at' => NiceDate::class,
|
|
];
|
|
|
|
protected $fillable = [
|
|
'message',
|
|
'to'
|
|
];
|
|
|
|
public function toCustomer()
|
|
{
|
|
return $this->belongsTo(Customers::class, 'to');
|
|
}
|
|
|
|
public function fromCustomer()
|
|
{
|
|
return $this->belongsTo(Customers::class, 'from');
|
|
}
|
|
|
|
public static function getMessagesOlderThan(int $days)
|
|
{
|
|
return Message::where('updated_at', '<', Carbon::now()->subDays($days));
|
|
}
|
|
|
|
public function notifiable()
|
|
{
|
|
return $this->morphOne(Notifications::class, 'notifiable');
|
|
}
|
|
}
|