Вход Регистрация
Файл: vendor/laravel/framework/src/Illuminate/Notifications/DatabaseNotification.php
Строк: 112
<?php

namespace IlluminateNotifications;

use 
IlluminateDatabaseEloquentBuilder;
use 
IlluminateDatabaseEloquentHasCollection;
use 
IlluminateDatabaseEloquentModel;

class 
DatabaseNotification extends Model
{
    
/** @use HasCollection<DatabaseNotificationCollection> */
    
use HasCollection;

    
/**
     * The "type" of the primary key ID.
     *
     * @var string
     */
    
protected $keyType 'string';

    
/**
     * Indicates if the IDs are auto-incrementing.
     *
     * @var bool
     */
    
public $incrementing false;

    
/**
     * The table associated with the model.
     *
     * @var string
     */
    
protected $table 'notifications';

    
/**
     * The guarded attributes on the model.
     *
     * @var array
     */
    
protected $guarded = [];

    
/**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    
protected $casts = [
        
'data' => 'array',
        
'read_at' => 'datetime',
    ];

    
/**
     * The type of collection that should be used for the model.
     */
    
protected static string $collectionClass DatabaseNotificationCollection::class;

    
/**
     * Get the notifiable entity that the notification belongs to.
     *
     * @return IlluminateDatabaseEloquentRelationsMorphTo<IlluminateDatabaseEloquentModel, $this>
     */
    
public function notifiable()
    {
        return 
$this->morphTo();
    }

    
/**
     * Mark the notification as read.
     *
     * @return void
     */
    
public function markAsRead()
    {
        if (
is_null($this->read_at)) {
            
$this->forceFill(['read_at' => $this->freshTimestamp()])->save();
        }
    }

    
/**
     * Mark the notification as unread.
     *
     * @return void
     */
    
public function markAsUnread()
    {
        if (! 
is_null($this->read_at)) {
            
$this->forceFill(['read_at' => null])->save();
        }
    }

    
/**
     * Determine if a notification has been read.
     *
     * @return bool
     */
    
public function read()
    {
        return 
$this->read_at !== null;
    }

    
/**
     * Determine if a notification has not been read.
     *
     * @return bool
     */
    
public function unread()
    {
        return 
$this->read_at === null;
    }

    
/**
     * Scope a query to only include read notifications.
     *
     * @param  IlluminateDatabaseEloquentBuilder<static>  $query
     * @return IlluminateDatabaseEloquentBuilder<static>
     */
    
public function scopeRead(Builder $query)
    {
        return 
$query->whereNotNull('read_at');
    }

    
/**
     * Scope a query to only include unread notifications.
     *
     * @param  IlluminateDatabaseEloquentBuilder<static>  $query
     * @return IlluminateDatabaseEloquentBuilder<static>
     */
    
public function scopeUnread(Builder $query)
    {
        return 
$query->whereNull('read_at');
    }
}
Онлайн: 1
Реклама