HasDatabaseNotifications.php
TLDR
The file HasDatabaseNotifications.php
contains a trait called HasDatabaseNotifications
that provides methods to manage notifications for an entity.
Methods
notifications
This method returns the notifications associated with the entity.
- Returns:
Illuminate\Database\Eloquent\Relations\MorphMany
object.
readNotifications
This method returns the read notifications associated with the entity.
- Returns:
Illuminate\Database\Query\Builder
object.
unreadNotifications
This method returns the unread notifications associated with the entity.
- Returns:
Illuminate\Database\Query\Builder
object.
<?php
namespace Illuminate\Notifications;
trait HasDatabaseNotifications
{
/**
* Get the entity's notifications.
*
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
*/
public function notifications()
{
return $this->morphMany(DatabaseNotification::class, 'notifiable')->latest();
}
/**
* Get the entity's read notifications.
*
* @return \Illuminate\Database\Query\Builder
*/
public function readNotifications()
{
return $this->notifications()->read();
}
/**
* Get the entity's unread notifications.
*
* @return \Illuminate\Database\Query\Builder
*/
public function unreadNotifications()
{
return $this->notifications()->unread();
}
}