Skip to content

Commit

Permalink
Message and Notifiable should be able to handle Mailable.
Browse files Browse the repository at this point in the history
Signed-off-by: crynobone <crynobone@gmail.com>
  • Loading branch information
crynobone committed Jul 28, 2016
1 parent 25013cd commit 09de6f3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
13 changes: 13 additions & 0 deletions src/Message.php
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Support\Arr;
use Illuminate\Support\Fluent;
use Illuminate\Contracts\Mail\Mailable as MailableContract;
use Orchestra\Contracts\Notification\Message as MessageContract;

class Message extends Fluent implements MessageContract
Expand Down Expand Up @@ -55,4 +56,16 @@ public function getView()
{
return Arr::get($this->attributes, 'view');
}

/**
* Is message mailable.
*
* @return bool
*/
public function mailable()
{
$view = $this->getView();

return ($view instanceof MailableContract);
}
}
10 changes: 7 additions & 3 deletions src/Notifiable.php
Expand Up @@ -40,14 +40,18 @@ protected function sendNotifications(Collection $users, $subject, $view = null,
*/
protected function sendNotification(Recipient $user, $subject, $view = null, array $data = [])
{
$entity = $user;

if ($subject instanceof MessageContract) {
$data = $subject->getData();
if ($subject->mailable()) {
return Notifier::send($user, $subject);
}

$view = $subject->getView();
$data = $subject->getData();
$subject = $subject->getSubject();
}

$entity = $user;

if ($user instanceof Arrayable) {
$entity = $user->toArray();
}
Expand Down

0 comments on commit 09de6f3

Please sign in to comment.