71 lines
1.6 KiB
PHP
71 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace kernel\modules\notification\models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use kernel\modules\user\models\User;
|
|
|
|
/**
|
|
* @property int $id
|
|
* @property int $user_id
|
|
* @property bool $is_read
|
|
* @property array|string $data
|
|
* @property string $type
|
|
* @property string $message
|
|
* @property string $subject
|
|
* @property int $status
|
|
*/
|
|
|
|
class Notification extends Model
|
|
{
|
|
const DISABLE_STATUS = 0;
|
|
const TO_SEND_STATUS = 1;
|
|
const SENT_STATUS = 2;
|
|
|
|
protected $table = 'notification';
|
|
|
|
protected $fillable = ['user_id', 'message', 'is_read', 'data', 'type', 'subject', 'status'];
|
|
|
|
protected $casts = [
|
|
'is_read' => 'boolean',
|
|
'data' => 'array'
|
|
];
|
|
|
|
public static function labels(): array
|
|
{
|
|
return [
|
|
'user_id' => 'Пользователь',
|
|
'message' => 'Сообщение',
|
|
'subject' => 'Тема',
|
|
'is_read' => 'Прочитано',
|
|
'data' => 'Данные',
|
|
'type' => 'Тип',
|
|
'status' => 'Статус'
|
|
];
|
|
}
|
|
|
|
public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
public function markAsRead(): static
|
|
{
|
|
$this->update(['is_read' => true]);
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return string[]
|
|
*/
|
|
public static function getStatus(): array
|
|
{
|
|
return [
|
|
self::DISABLE_STATUS => "Не активный",
|
|
self::TO_SEND_STATUS => "На отправку",
|
|
self::SENT_STATUS => "Отправлено",
|
|
];
|
|
}
|
|
|
|
} |