Framework: [5.6] Notifications - generate or supply a render() similar to mail for previewing

Created on 2 May 2018  路  3Comments  路  Source: laravel/framework

Right now I have a route that does this:

use \Illuminate\Mail\Markdown;

use App\Models\User;
use App\Models\License;
use App\Notifications\ContentLicense;

Route::get('/mailable/content-license', function() {
  $license = License::with(['content', 'user'])->inRandomOrder()->get()->first();
  $message = (new ContentLicense($license))->toMail(User::first());
  return app(Markdown::class)->render($message->markdown, $message->data());
});

another option I explored is putting render() inside the Notification class

// Notifications/ContentLicense.php

  public function render($notifiable)
  {
    // $markdown = new \Illuminate\Mail\Markdown(view(), config('mail.markdown'));
    $message = $this->toMail($notifiable);
    return app(Markdown::class)->render($message->markdown, $this->toArray($notifiable));
  }

...
// route

Route::get('/mailable/content-license', function() {
  $license = License::with(['content', 'user'])->inRandomOrder()->get()->first();
  return (new ContentLicense($license))->render(User::first());
});

I think it'd be a cool feature similar to using Mail, I could PR a solution but I know that it would be good to support \Illuminate\Contracts\Support\Renderable which takes no parameters, where w/ this we need to pass in a type of $notifiable.

If anyone has any other ideas how this could be done LMK!

Most helpful comment

I'd like to see this reopened. It would be nice to see \Illuminate\Auth\Notifications\ResetPassword using a simple $mailMessage->render() method, just as it works for Mailable objects.

All 3 comments

This issue reads like a chat entry. What do you want to accomplish with this issue?

@sisve it's quite simple, mailable's have a render() allowing them to be rendered on the web. Documentation can be found here . This is not possible for MailMessage mails from Notifications. I'm proposing we add it.

This way people aren't having to write what I did above, or google it and find stuff like this

I'd like to see this reopened. It would be nice to see \Illuminate\Auth\Notifications\ResetPassword using a simple $mailMessage->render() method, just as it works for Mailable objects.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gabriellimo picture gabriellimo  路  3Comments

Fuzzyma picture Fuzzyma  路  3Comments

JamborJan picture JamborJan  路  3Comments

CupOfTea696 picture CupOfTea696  路  3Comments

felixsanz picture felixsanz  路  3Comments