Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.6] Allow notification routing to depend on notification being sent #22289

Merged
merged 4 commits into from
Dec 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions CHANGELOG-5.5.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# Release Notes for 5.5.x

## [Unreleased]

### Added
- Added a `Collection::firstWhere()` method ([#22261](https://github.com/laravel/framework/pull/22261), [#22264](https://github.com/laravel/framework/pull/22264))
- Added several accessors to `BelongsToMany` ([f09ea98](https://github.com/laravel/framework/commit/f09ea98bc814c708215896dad702d715923f3bc3), [cbe8123](https://github.com/laravel/framework/commit/cbe8123a479e81779cd85251eb4a5cf861e93ea3), [3bcf9d1](https://github.com/laravel/framework/commit/3bcf9d1d67ca3f288270e910898c77334322128a))

### Changed
- Pass test value to `Collection::when()` callbacks ([#22224](https://github.com/laravel/framework/pull/22224))
- Support worker sleep time of less than 1s ([#22246](https://github.com/laravel/framework/pull/22246), [#22255](https://github.com/laravel/framework/pull/22255))
- Detect persistent connection resets ([#22277](https://github.com/laravel/framework/pull/22277))

### Fixed
- Fixed negative comparison to objects in `Collection::where()` ([#22256](https://github.com/laravel/framework/pull/22256))
- Fixed integer validation using `distinct:ignore_case` ([#22235](https://github.com/laravel/framework/pull/22235))
- Fixes building nested JSON accessors in `MySqlGrammar` ([#22254](https://github.com/laravel/framework/pull/22254))


## v5.5.22 (2017-11-27)

### Added
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Notifications/Channels/DatabaseChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class DatabaseChannel
*/
public function send($notifiable, Notification $notification)
{
return $notifiable->routeNotificationFor('database')->create([
return $notifiable->routeNotificationFor('database', $notification)->create([
'id' => $notification->id,
'type' => get_class($notification),
'data' => $this->getData($notifiable, $notification),
Expand Down
14 changes: 8 additions & 6 deletions src/Illuminate/Notifications/Channels/MailChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function send($notifiable, Notification $notification)
{
$message = $notification->toMail($notifiable);

if (! $notifiable->routeNotificationFor('mail') &&
if (! $notifiable->routeNotificationFor('mail', $notification) &&
! $message instanceof Mailable) {
return;
}
Expand Down Expand Up @@ -109,7 +109,7 @@ protected function buildView($message)
*/
protected function buildMessage($mailMessage, $notifiable, $notification, $message)
{
$this->addressMessage($mailMessage, $notifiable, $message);
$this->addressMessage($mailMessage, $notifiable, $message, $notification);

$mailMessage->subject($message->subject ?: Str::title(
Str::snake(class_basename($notification), ' ')
Expand All @@ -128,13 +128,14 @@ protected function buildMessage($mailMessage, $notifiable, $notification, $messa
* @param \Illuminate\Mail\Message $mailMessage
* @param mixed $notifiable
* @param \Illuminate\Notifications\Messages\MailMessage $message
* @param \Illuminate\Notifications\Notification $notification
* @return void
*/
protected function addressMessage($mailMessage, $notifiable, $message)
protected function addressMessage($mailMessage, $notifiable, $message, $notification)
{
$this->addSender($mailMessage, $message);

$mailMessage->to($this->getRecipients($notifiable, $message));
$mailMessage->to($this->getRecipients($notifiable, $message, $notification));

if ($message->cc) {
$mailMessage->cc($message->cc[0], Arr::get($message->cc, 1));
Expand Down Expand Up @@ -168,11 +169,12 @@ protected function addSender($mailMessage, $message)
*
* @param mixed $notifiable
* @param \Illuminate\Notifications\Messages\MailMessage $message
* @param \Illuminate\Notifications\Notification $notification
* @return mixed
*/
protected function getRecipients($notifiable, $message)
protected function getRecipients($notifiable, $message, $notification)
{
if (is_string($recipients = $notifiable->routeNotificationFor('mail'))) {
if (is_string($recipients = $notifiable->routeNotificationFor('mail', $notification))) {
$recipients = [$recipients];
}

Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Notifications/Channels/NexmoSmsChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function __construct(NexmoClient $nexmo, $from)
*/
public function send($notifiable, Notification $notification)
{
if (! $to = $notifiable->routeNotificationFor('nexmo')) {
if (! $to = $notifiable->routeNotificationFor('nexmo', $notification)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __construct(HttpClient $http)
*/
public function send($notifiable, Notification $notification)
{
if (! $url = $notifiable->routeNotificationFor('slack')) {
if (! $url = $notifiable->routeNotificationFor('slack', $notification)) {
return;
}

Expand Down
5 changes: 3 additions & 2 deletions src/Illuminate/Notifications/RoutesNotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ public function notifyNow($instance, array $channels = null)
* Get the notification routing information for the given driver.
*
* @param string $driver
* @param \Illuminate\Notifications\Notification|null $notification
* @return mixed
*/
public function routeNotificationFor($driver)
public function routeNotificationFor($driver, $notification = null)
{
if (method_exists($this, $method = 'routeNotificationFor'.Str::studly($driver))) {
return $this->{$method}();
return $this->{$method}($notification);
}

switch ($driver) {
Expand Down