Files
nexusphp/app/Models/Message.php

36 lines
736 B
PHP
Raw Normal View History

<?php
namespace App\Models;
2022-07-23 15:05:32 +08:00
use Nexus\Database\NexusDB;
class Message extends NexusModel
{
protected $table = 'messages';
protected $fillable = [
'sender', 'receiver', 'added', 'subject', 'msg', 'unread', 'location', 'saved'
];
2021-05-15 19:29:44 +08:00
protected $casts = [
'added' => 'datetime',
];
public function send_user()
{
return $this->belongsTo(User::class, 'sender')->withDefault(['id' => 0, 'username' => 'System']);
}
public function receive_user()
{
return $this->belongsTo(User::class, 'receiver');
}
2022-07-23 15:05:32 +08:00
public static function add(array $data): bool
{
2023-02-08 13:33:25 +08:00
clear_inbox_count_cache($data["receiver"]);
2022-07-23 15:05:32 +08:00
return self::query()->insert($data);
}
}