Skip to content

Commit 962846d

Browse files
committed
Recipients spread.
1 parent d7ed07e commit 962846d

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/Models/MailatorSchedule.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,11 +274,13 @@ public function constraint(SendScheduleConstraint $constraint): self
274274
return $this;
275275
}
276276

277-
public function recipients(array $recipients): self
277+
public function recipients(...$recipients): self
278278
{
279-
$this->recipients = collect($recipients)
279+
$this->recipients = array_merge(collect($recipients)
280+
->flatten()
280281
->filter(fn ($email) => $this->ensureValidEmail($email))
281-
->toArray();
282+
->unique()
283+
->toArray(), $this->recipients ?? []);
282284

283285
return $this;
284286
}

tests/Feature/Models/MailatorScheduleTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,4 +284,24 @@ public function test_can_handle_custom_action()
284284

285285
MailatorSchedule::run();
286286
}
287+
288+
public function test_recipients_merges()
289+
{
290+
Mail::fake();
291+
292+
$scheduler = MailatorSchedule::init('Invoice reminder.')
293+
->recipients(
294+
$mail = 'zoo@bar.com',
295+
);
296+
297+
self::assertSame([$mail], $scheduler->recipients);
298+
299+
$scheduler->recipients([$mail2 = 'foo@bar.com']);
300+
301+
self::assertSame([$mail2, $mail], $scheduler->recipients);
302+
303+
$scheduler->recipients($mail3 = 'too@bar.com');
304+
305+
self::assertSame([$mail3, $mail2, $mail], $scheduler->recipients);
306+
}
287307
}

0 commit comments

Comments
 (0)