Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
187 views
in Technique[技术] by (71.8m points)

php - How to call public function inside mailable markdown template?

What I'm doing here is, I am inviting the users to the platform. So, basically I'm calling for a public function from the invitation model, which generates an invitation link based on the token. I am unable to set the link inside the button component of the markdown mailable template. As I cant call the {{ $invitation->getLink() }} inside the single quotes. Sorry for being a noob, please help me down here.

  • Models/Invitation.php
public function generateToken() {
       $this->token = substr(md5(rand(0, 9) . $this->email . time()), 0, 32);
}

public function getLink() {
       return urldecode(route('register') . '?token=' . $this->token);
}
  • views/mails/invitation-email.blade.php
@component('mail::message')
# Introduction

The body of your message.

@component('mail::button', ['url' => '{{ $invitation->getLink() }}'])
Button Text
@endcomponent

Thanks,<br>
{{ config('app.name') }}
@endcomponent

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Remove the '{{ }}' attached to the URL like this

@component('mail::button', ['url' => $invitation->getLink()]) Button Text @endcomponent

I hope this help, you can get more info: https://laravel.com/docs/8.x/mail#generating-markdown-mailables


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...