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();
}
/** @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()); }