在Markdown邮件模板中使用Trait的问题

时间:2019-04-11 15:26:29

标签: php laravel traits

我试图在laravel的markdown邮件模板中使用php Trait方法,问题是出现以下错误:

BroadcastReceiver

我正在尝试使用Strings php Trait类中的getExcerpt方法,但无法正常工作。

这是我的可邮寄课程:

ACTION_BOOT_COMPLETED

我的降价邮件模板:

 ErrorException  : Call to undefined method Illuminate\View\Engines\CompilerEngine::getExcerpt() (View: C:\xampp\htdocs\dtcburger.com\resources\views\emails\weekly\weekly-mail-1.blade.php)

还有我的Strings Trait,里面有方法getExcerpt:

<?php
namespace App\Mail\weekly;


use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
use App\Traits\Strings;


class WeeklyMail1 extends Mailable
{


    use Queueable, SerializesModels;
    use Strings;
    public $mailData;


    public function __construct($mailData)
    {
        $this->mailData = $mailData;
    }


    public function build()
    {
        $mail = $this->markdown('emails.weekly.weekly-mail-1')
        ->from(env('MAIL_FROM'), env('MAIL_FROM_NAME'))
        ->subject($this->mailData['subject']);

        return $mail;
    }


}

1 个答案:

答案 0 :(得分:0)

这是因为您不再在WeeklyMail类上下文中。

我建议您只是对事件模型进行访问

.sort()

然后在您的模板中


use Strings;

function getExcerptBodyAttribute(){
      return $this->getExcerpt($this->body, 0, 100)
}

如果您的活动不是雄辩的榜样,请让塞特做一个设置他的<img src="{{ $event->image }}" style="min-width:120px; max-width:120px; min-height:100px; max-height:100px;"> | <strong><p>{{ $event->title }}</p></strong><p>{{!! $event->excerpt_body !!}}</p>