Hi I am trying to use MailMessage function in my Laravel App. My question is very simple. How to edit the Header and the Footer when receiving email from the app? Here is the picture below.
I want to change the header Laravel from my App name and the Hello with a Hello $user->name and the Regards, with my App name also and the footer below to the App name also.
I tried to change the `
resources/views/vendor/mail/markdown/message.blade.php
To:
#component('mail::layout')
{{-- Header --}}
#slot('header')
#component('mail::header', ['url' => config('app.url')])
CCTV App
#endcomponent
#endslot
{{-- Body --}}
{{ $slot }}
{{-- Subcopy --}}
#isset($subcopy)
#slot('subcopy')
#component('mail::subcopy')
CCTV Team
#endcomponent
#endslot
#endisset
{{-- Footer --}}
#slot('footer')
#component('mail::footer')
© {{ date('Y') }} CCV3. All rights reserved.
#endcomponent
#endslot
#endcomponent
But not working when I send a reset password request
Would really appreciate if someone can help me.
Thanks in advance.
`
I want to change the header Laravel from my App name and the Hello with a Hello $user->name and the Regards, with my App name also and the footer below to the App name also
Mailable Markdown by default has the config('app.name') that picks the APP_NAME from your .env file. So by modifying the APP_NAME will effect on your markdown template.
OR if you modifying it manually, run the following command on your terminal
php artisan vendor:publish --tag=laravel-mail and go to the resources/views/vendor/mail/html/message.blade.php and modify the header and footer slot.
For changing Hello to Hello {user_name}, there is markdown called greeting() method that holds Hello!, you can change it whatever you want.
For Regards run this command on your terminal
php artisan vendor:publish --tag=laravel-notifications and go to the resources/views/vendor/notifications/email.blade.php and modify the Regards whatever you want.
To know more in details take a look on customizing markdown email.
I already figure it out just change the name of the env file to your App name instead of laravel. This is the sample below.
APP_NAME=Laravel
Change it to
APP_NAME=YOUR_APP_NAME
there is also one way to edit your mail template.
Just go to resources/views/vendor/notifications/email.blade.php
and you can also edit the message to your mail just go to resources/views/vendor/markdown/message.blade.php
You are using default component for your email template named #component('mail::message'), It does not allow you to modify header. But if you go to the file of this component,
\vendor\laravel\framework\src\Illuminate\Mail\resources\views\markdown\message.blade.php
you will notice that it uses another component #component('mail::layout'),
Just copy content of message.blade.php file into your .blade.php and replace {{ $slot }} with what you had in your file before.
And you are done.
Related
I'm trying to add a github author's reference system project to my project. I did everything but stuck on the last step. He gave me the code to get the reference link, but I don't know where or in which file to add it.
Here GitHub link: https://github.com/questocat/laravel-referral
step where i got stuck and don't know where to add;
$user = App\User::findOrFail(1);
{{ $user->getReferralLink() }}
I tried doing
<p>{{ $user->getReferralLink() }} </p>
on a sample page, but it didn't work. I would be glad if you help.
I have the issue in which when I am writing the components in Laravel Mailable, according to their 6.x documentation (since my Laravel version is 6.0). But despite that, in the actual email some components render properly, some are just plain HTML. By plain HTML I mean the text literally says <a>...</a>, but doesn't render the actual element.
Why would that be? Maybe there is a bug, or I am missing something? I have written the most regular email with the components provided by Laravel's docs. There is no linter errors. The view is written in blade btw.
#section('content')
#foreach ($paragraphs as $item)
<p> {{ $item }} </p>
#endforeach
#component('mail::button', [ 'url' => $link ])
{{ $buttonText }}
#endcomponent
#endsection
I resolved the issue. The issue disappeared when I removed any possible indentation in the file.
When every single line started at column 0, the components rendered properly.
Documentation (at least 6.x) doesn't say anything about that, so I assume this is a bug with blade/php mailing compilation or something.
I am trying to pick the master blade template dynamically as per the current user roll logged in. (here it should go to the 'shopowner' auth block)
#auth('shopmanager')
#extends('theme::Admins.shopmanager.layout.master')
#endauth
#auth('shopowner')
#extends('theme::Admins.shopowner.layout.master')
#endauth
but this always gives error as it tries to compile the 'shopmanager' master template. It is not going into the 'shopmanager' #auth block because it's not printing anything if I print inside that block.
It only works if I completely comment out that line.
P.S.:
This is the master theme::Admins.shopmanager.layout.master template file
which must not be loaded.
#extends('theme::Admins.outline.layout.master')
#include('theme::Admins.shopmanager.layout.common.header')
#include('theme::Admins.shopmanager.layout.common.left-sidebar') // The error throws from inside this view.
#include('theme::Admins.shopmanager.layout.common.footer')
#section('title-head', __('Shop Manager'))
I can wrap the #auth check around #include lines but the point is, this complete file should be skipped from the compilation.
SOLVED
As per my learning, #extend(...) will always be compiled regardless of outer wrap conditions. so must be moved to dynamic variable based blocks.
#auth('shopmanager')
#php
$masterTemplate = 'theme::Admins.shopmanager.layout.master';
#endphp
#endauth
#auth('shopowner')
#php
$masterTemplate = 'theme::Admins.shopowner.layout.master';
#endphp
#endauth
#extends($masterTemplate)
Try below code ,i hope this ans help you:
#if(Auth::check())
#if(Auth::user()->role=='shopmanager')
#extends('theme::Admins.shopmanager.layout.master')
#else
#extends('theme::Admins.shopowner.layout.master')
#endif
#endif
If you have multi-authentication that time try below :
#if(Auth::guard('shopmanager')->user())
#extends('')
#else
#extends('')
#endif
In my case, I'm handling manager, customer and admin with this code.
Manager : Auth::guard('manager')->user()
Admin : Auth::user()
Customer : Auth::guard('customer')->user()
I'm trying to embed an image into my markdown email but it's not loading correctly.
https://i.imgur.com/lNCwhod.png
This is my mail template:
#component('mail::message')
# {{ $mailData['title'] }}
![{{ $mailData['appName'] }}]({{ asset($mailData['image'])}})
{!! $mailData['body'] !!}
Saludos,
{{ $mailData['appName'] }}
#endcomponent
This is the value of $mailData['image']:
'/img/misc/default.jpg'
Any idea how I can do this?
You can use html to add an image to your markdown:
#component('mail::message')
# {{ $mailData['title'] }}
<img src="{{asset('img/logo.png')}}" style="width:30%" alt="App Logo">
...
#endcomponent
Also you can use the style tag to customize the image.
Be aware if you are in localhost, you aren't going to see the image in the email (unless you are using mailhogh to test your emails).
As far as I know, the image has to be in your server hosted, so the image will not attached on the email.
Your server need an IP public or a domain to be able to see the images within the email.
You can try this markdown:
![Image_Alter_Text](PAHT_OF_IMAGE)
You have to pass complete path of image, and you get complete path by using Storage::url($file_name). Store image path in variable and pass in markdown.
For example :
![DemoImage](https://i.stack.imgur.com/bENi3.jpg)
Note: The image (logo of stackoverflow) is used in this comments is only for demo purpose.
i'm displaying external Website Links from my Users in a Profile Page. The URL Format is: www.xyz.com. When i put a http:// before the {{ url }} Laravel changes the Protocoll automatically to https://. In the Result a lot of the Websites don't open properly. I set the APP_URL in the .env File to
https://domain because i want to use SSL in the App.
Laravel (Blade) is removing the http:// from the URL when i just want to print the Variable too. Even when i put http:// right in front the URL in the DB (MySQL) i still have the same problem.
All i do in the Controller is:
$user = \App\User::find($id);
After 2 days of research i'm reaching out to the community. Basically i'm searching for something like secure_url() inverse.
What i tried:
{{ url('http://'.$url) }}
{!! url('http://'.$url) !!}
{!! url(e('http://'.$url)) !!}
<a href="http://{{ $url }}">
{{ $url }}
Putting the Protocoll right in the DB
What do i not get here? Thank you for any help.
EDIT
Laravel does this only when i visit my site over https.
UPDATE & SOLUTION
It was the problem of the Laravel Cache Speed Package. I deactivated it and everything was back to normal. My fault, my bad.