我正在为我的应用程序构建邮件,但我一直在尝试使用nl2br,因为人们可以在其中写入。现在我有了这段代码:
{!! nl2br($text['text']) !!}
我把它放在一个数组中,因为有人说它有效,但事实并非如此,我的结果真的很奇怪:
所以它添加了添加第一行的结尾然后添加正确的行结尾。我以前从未见过这种行为。
这是刀片降价文件中的完整代码:
@component('mail::layout')
{{-- Header --}}
@slot('header')
@component('mail::header', ['url' => config('app.url')])
<img src="https://www.cpned.nl/wp-content/uploads/2014/12/cpned-logo.png" height="75px">
@endcomponent
@endslot
<h1>Goedendag!</h1>
{!! nl2br($text['text']) !!}
Met vriendelijke groeten, {{PHP_EOL}}
{{PHP_EOL}}
Het Circulation Practitioners Intranet.
{{-- Footer --}}
@slot('footer')
@component('mail::footer')
© {{ date('Y') }} Circulation Practitioners. Alle rechten voorbehouden <br/>
Deze mail is gegenereert door het intranet, u kunt hierop niet reageren!
@endcomponent
@endslot
@endcomponent
以下是我的控制器:
Mail::to($users)->send(new Reminder($request->subject, array('text' => $request->message)));
然后是我的最后一个文件:
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
class Reminder extends Mailable
{
use Queueable, SerializesModels;
public $subject;
public $text;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($subject, $text)
{
$this->subject = $subject;
$this->text = $text;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this
->subject($this->subject)
->markdown('emails.reminder');
}
}
我一直在努力解决这个问题几个小时,我无法发现造成这种奇怪行为的问题。
提前致谢!
答案 0 :(得分:1)
你有没有尝试过更换
{!! nl2br($text['text']) !!}
{!!> {!! nl2br(e($ text ['text']))!!}