2017-10-06 23 views
0

我正在使用Laravel的Notifications系統在用戶註冊時發送歡迎郵件。一切都很好,除非我不能爲我的生活弄清楚如何在問候中插入換行符。如何在降價中插入換行符通知

這是我的代碼:

namespace App\Notifications\Auth; 

use Illuminate\Notifications\Notification; 
use Illuminate\Notifications\Messages\MailMessage; 


class UserRegistered extends Notification 
{ 

    public function via($notifiable) 
    { 
     return ['mail']; 
    } 

    public function toMail($notifiable) 
    { 
     return (new MailMessage) 
      ->subject('Welcome to website!') 
      ->greeting('Welcome '. $notifiable->name .'!') 
      ->line('## Sub heading line') 
      ->line('Paragraph line') 
      ->markdown('mail.welcome'); 
    } 
} 

我想在這裏把休息->greeting('Welcome '. $notifiable->name .'!')的歡迎和名之間。任何人都知道我可以做到這一點?我已經嘗試了markdown文檔中描述的雙倍空間。我試過使用nl2br()。我試過\ n。我試過<br>。什麼都沒有

+0

有你提到這個職位?
https://stackoverflow.com/questions/26626256/how-to-insert-a-line-break-br-in-markdown –

+0

是的。試過 –

+0

@ james.brndwgn在你的雙引號中使用
shashi

回答

0

它可能看起來很糟糕,但我認爲這可以工作:

->greeting("Welcome 
     ". $notifiable->name ."!") 

應該保持換行符,不幸的是我不能測試它現在

編輯:另一種選擇是使用不同的greeting電話:

return (new MailMessage) 
      ->subject('Welcome to website!') 
      ->greeting('Welcome') 
      ->greeting($notifiable->name .'!') 
      ->line('## Sub heading line') 
      ->line('Paragraph line') 
      ->markdown('mail.welcome'); 
0

得到它的工作。原來是在使用{{ }}時因Laravel轉義HTML而出現的問題。你必須防止逃逸通過{!! !!}Using double curly brace in Laravel Collective

對於那些有興趣我的問候語,現在->greeting('Welcome<br>'. $notifiable->name .'!')

,並在我的降價模板,它的

{{-- Greeting --}} 
@if (! empty($greeting)) 
# {!! $greeting !!} 
@endif 
相關問題