Doaa Magdy Doaa Magdy - 22 days ago 7
HTML Question

Laravel 5 Use standard view as an email template

I've a Laravel 5.0 project, that I need to send emails to users (such as registration confirmation mail, ... etc).

My problem is I want to create a view (that contains the header and footer of my App), and I want to use this view's html output as a template for the email message body (I need HTML output so I can get Full URLs for images and links to be sent in the email body).

My Question is, Is there any method that can work like curl, when I pass the view URL, This method grab the HTML source of this view?

I don't want to use custom packages for that, I need a native solution

Answer

Create basic email template in resources/views/mails/template.blade.php

header html...

@yield('content')

footer html...

And then in particular emails, for example resources/views/mails/confirmation.blade.php

@extends('mails.template')

@section('content')
    content of confirmations email...
@endsection

To store html of rendered view in a variable you can do

$view = View::make('mails.confirmation');
$html = $view->render();