Fenos\Notifynder\Notifications\NotificationRepository::deleteLimit PHP Method

deleteLimit() public method

Delete numbers of notifications equals to the number passing as 2 parameter of the current user.
public deleteLimit ( $userId, $entity, $number, $order ) : integer
$userId int
$entity
$number int
$order string
return integer
    public function deleteLimit($userId, $entity, $number, $order)
    {
        $notificationsIds = $this->notification->wherePolymorphic($userId, $entity)->orderBy('id', $order)->select('id')->limit($number)->lists('id');
        if (count($notificationsIds) == 0) {
            return false;
        }
        return $this->notification->whereIn('id', $notificationsIds)->delete();
    }

Usage Example

 /** @test */
 function it_delete_notifications_limit_the_number_of_the_given_entity()
 {
     $this->createMultipleNotifications();
     $notificationsDeleted = $this->notificationRepo->deleteLimit($this->to['id'], $this->to['type'], 5, 'asc');
     $this->assertEquals(5, $notificationsDeleted);
     $this->assertCount(5, Notification::all());
 }