Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

moses's avatar
Level 2

How can I display two table in email layout laravel 5.4?

I want to customize Laravel 5.4 Notification Email Templates

https://medium.com/@adnanxteam/how-to-customize-laravel-5-4-notification-email-templates-header-and-footer-158b1c7cc1c

On the vendor/mail/html/message.blade, I try like this :

@component('mail::layout')
    {{-- Header --}}
    @slot('header')
        @component('mail::header', ['url' => config('app.url')])
            {{ config('app.name') }}
        @endcomponent
    @endslot

    {{-- Body --}}
    This is table one
    @component('mail::table')
    | Laravel       | Table         | Example  |
    | ------------- |:-------------:| --------:|
    | Col 2 is      | Centered      | $10      |
    | Col 3 is      | Right-Aligned | $20      |
    @endcomponent

    This is table two
    @component('mail::table')
    | Laravel       | Table         | Example  |
    | ------------- |:-------------:| --------:|
    | Col 2 is      | Centered      | $10      |
    | Col 3 is      | Right-Aligned | $20      |
    @endcomponent

    {{-- Subcopy --}}
    @isset($subcopy)
        @slot('subcopy')
            @component('mail::subcopy')
                {{ $subcopy }}
            @endcomponent
        @endslot
    @endisset

    {{-- Footer --}}
    @slot('footer')
        @component('mail::footer')
            © {{ date('Y') }} {{ config('app.name') }}. All rights reserved.
        @endcomponent
    @endslot
@endcomponent

There are 2 tables. The first table appears well. But the second table, looks not neat. Seems the css does not work. And other than that the data after the table 1, the text is very small

The result of email layout like this :

enter image description here Why did it happen? Is my code is still wrong?

0 likes
3 replies
Jaytee's avatar

Seems like its being rendered as a code block as per the documentation. Theres a warning in the docs about using excess indentation. Try keep everything inbetween the main component with just one level of indentation and see if that works. If it does, try indenting others to achieve a more readable file up until it breaks.

Simple debugging stuff. Alternatively, don't use markdown mailables.

migsAV's avatar

Try using only one set of @component('mail::table') so instead of

 @component('mail::table')
    | Laravel       | Table         | Example  |
    | ------------- |:-------------:| --------:|
    | Col 2 is      | Centered      |       |
    | Col 3 is      | Right-Aligned |       |
    @endcomponent

    This is table two
    @component('mail::table')
    | Laravel       | Table         | Example  |
    | ------------- |:-------------:| --------:|
    | Col 2 is      | Centered      |       |
    | Col 3 is      | Right-Aligned |       |
    @endcomponent

use the following

 @component('mail::table')
    | Laravel       | Table         | Example  |
    | ------------- |:-------------:| --------:|
    | Col 2 is      | Centered      |       |
    | Col 3 is      | Right-Aligned |       |


    | Laravel       | Table         | Example  |
    | ------------- |:-------------:| --------:|
    | Col 2 is      | Centered      |       |
    | Col 3 is      | Right-Aligned |       |
    @endcomponent
Marghen's avatar

For anyone encountering the same problem, It's the newline in the code. Remove any newlines (spaces in between lines of code) otherwise for some reason that happens. With any markdown email, still in Laravel 7.x

Please or to participate in this conversation.