Fenos\Notifynder\Models\Notification::scopeWherePolymorphic PHP Method

scopeWherePolymorphic() public method

Where Polymorphic.
public scopeWherePolymorphic ( $query, $toId, $type ) : mixed
$query
$toId
$type
return mixed
    public function scopeWherePolymorphic($query, $toId, $type)
    {
        if (!$type or config('notifynder.polymorphic') === false) {
            return $query->where('to_id', $toId);
        }
        return $query->where('to_id', $toId)->where('to_type', $type);
    }

Usage Example

 /**
  * Delete All notifications about the
  * current user
  *
  * @param $to_id int
  * @param $entity
  * @return Bool
  */
 public function deleteAll($to_id, $entity)
 {
     $query = $this->db->table($this->notification->getTable());
     return $this->notification->scopeWherePolymorphic($query, $to_id, $entity)->delete();
 }