We are sending email notifications using laravel notifications and mailable class.
We have the following process : ** We are using laravel 7 **
We dispatch the JOB
dispatch(new JobEntitiesEmail($arr,$email));
JobEntitiesEmail is a job we specifically wrote to send NOTIFICATIONS
`]
class JobEntitiesEmail implements ShouldQueue
{ use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Create a new job instance.
*
* @return void
*/
public $tries = 3;
public $arr;
public $email;
public function __construct($arr,$email)
{
$this->arr = $arr;
$this->email = $email;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
Notification::route('mail',$this->email)->notify((new EntitiesEmail($this->arr))->locale($this->arr['user_lang']));
}
}
- We have app\Notifications\EntitiesEmail.php where we are creating a MailMessage object.
$mailmessage= (new MailMessage)->subject("subject of mail")
->line( __('messages.hello'))
->line(new HtmlString(__('messages.email_message')))
->action(__('titles.click'), url("google.com"));
- We have an email template in Resources\View\Vendors\mail
- Both Email and Markdown ** We want to pass logo to the header file of mail which is located in resources\views\vendor\mail\html\header.blade.php**
like this :
$mailmessage= (new MailMessage)
->subject("email_template")
->line( __('messages.hello')..',')
->line(new HtmlString(__('messages.email_message')))
->action(__('titles.link'), url($link));
}
Also want to access the passed variable $logoUrl in file resources\views\vendor\mail\html\message.blade.php
like
@component('mail::layout')
{{-- Header --}}
@slot('header')
@component('mail::header', ['url' => config('app.url'), 'logoUrl' => $logoUrl ]) {{ config('app.name') }}
@endcomponent
@endslot
{{-- Body --}}
{{ $slot }}
{{-- Subcopy --}}
@isset($subcopy)
@slot('subcopy')
@component('mail::subcopy')
{{ $subcopy }}
@endcomponent
@endslot
@endisset
{{-- Footer --}}
@slot('footer')
@component('mail::footer')
© {{ date('Y') }} <a href="https://google.com">{{ config('app.name') }}</a>. @lang(__('messages.copyright'))
@endcomponent
@endslot
@endcomponent `
We have tried
- Using with method
$mailmessage= (new MailMessage)
->subject('New order')
->with(['logoUrl' => $logoUrl ])
It give data as a outrolines.
- Using Markdown
$mailmessage= (new MailMessage)
->subject('New order')
->markdown('Notification::email', ['logoUrl' => $logoUrl ]);
We get this data in viewData but not able to access this in template files.