Fenos\Notifynder\Notifications\NotificationRepository::storeMultiple PHP Méthode

storeMultiple() public méthode

Save multiple notifications sent at once.
public storeMultiple ( array $notifications ) : mixed
$notifications array
Résultat mixed
    public function storeMultiple(array $notifications)
    {
        $this->db->beginTransaction();
        $stackId = $this->db->table($this->notification->getTable())->max('stack_id') + 1;
        foreach ($notifications as $key => $notification) {
            $notifications[$key]['stack_id'] = $stackId;
        }
        $insert = $this->db->table($this->notification->getTable())->insert($notifications);
        $this->db->commit();
        return $insert;
    }

Usage Example

 /** @test */
 function it_send_multiple_notification()
 {
     $notificationsToSend[0] = $this->buildNotification();
     $notificationsToSend[1] = $this->buildNotification();
     $storeMultipleNotificaations = $this->notificationRepo->storeMultiple($notificationsToSend);
     $notifications = Notification::all();
     $this->assertCount(2, $notifications);
     $this->assertEquals(2, $storeMultipleNotificaations);
 }