Notification.php 1.3 KB
<?php

namespace App\Models;

use App\Support\Model;
use Awobaz\Compoships\Database\Eloquent\Relations\BelongsTo;
use Awobaz\Compoships\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;

class Notification extends Model
{
    use SoftDeletes;

    protected $table = 'notifications';

    protected $guarded = [];

    protected $hidden = ['deleted_at'];

    protected $casts = [
        'publish_to'   => 'array',
        'publish_type' => 'int'
    ];


    public array $columnMap = [
        'title'        => '通知标题',
        'content'      => '通知整文',
        'type'         => '类型',
        'cover'        => '图片',
        'link_type'    => "交互类型",
        'link_id'      => "交互对象",
        'publish_to'   => '发布对象',
        'publish_type' => "发布方式",
        'publish_at'   => '发布时间',
        'rich_content' => '富文本内容'
    ];


    /**
     * @return \Awobaz\Compoships\Database\Eloquent\Relations\BelongsTo
     */
    public function user(): BelongsTo
    {
        return $this->belongsTo(User::class)->withTrashed();
    }

    /**
     * @return \Awobaz\Compoships\Database\Eloquent\Relations\HasMany
     */
    public function items(): HasMany
    {
        return $this->hasMany(NotificationUser::class);
    }
}