ldc-legaulois/app/Models/Message.php

41 lines
777 B
PHP
Raw Normal View History

2021-03-10 17:16:31 +01:00
<?php
namespace App\Models;
use App\Casts\NiceDate;
use Illuminate\Database\Eloquent\Model;
2021-03-11 08:22:31 +01:00
use Illuminate\Support\Carbon;
2021-03-10 17:16:31 +01:00
class Message extends Model
{
2021-03-20 14:38:15 +01:00
2021-03-10 17:16:31 +01:00
protected $casts = [
'created_at' => NiceDate::class,
];
2021-03-20 14:38:15 +01:00
2021-03-10 17:16:31 +01:00
protected $fillable = [
'message',
'to'
];
public function toCustomer()
{
return $this->belongsTo(Customers::class, 'to');
}
public function fromCustomer()
{
return $this->belongsTo(Customers::class, 'from');
}
2021-03-11 08:22:31 +01:00
public static function getMessagesOlderThan(int $days)
{
return Message::where('updated_at', '<', Carbon::now()->subDays($days));
}
public function notifiable()
{
return $this->morphOne(Notifications::class, 'notifiable');
}
2021-03-10 17:16:31 +01:00
}