对象无法转换为字符串
问题描述:
我使用Laravel 5.5尝试发送电子邮件,但得到的错误类照亮\邮件\消息对象无法转换为字符串
对象无法转换为字符串
这里是我的控制器
public function contactreply($contact, Request $request){
$reply = new Reply;
$reply->subject = $request->subject;
$reply->message = $request->message;
$reply->email = $contact;
$reply->save();
$mail = Mail::to($contact)->send(new ContactReply($reply));
return Redirect::back()->with('status', 'Email Sent Success');
}
这里是我的ContactReply.php
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
class ContactReply extends Mailable
{
use Queueable, SerializesModels;
protected $reply;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($reply)
{
$this->reply = $reply; //dd($reply) passing all value here
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->view('admin.contact.reply')
->subject($this->reply->subject)
->with([
'message' => $this->reply->message,
]);
}
}
我查看文件
<div>
{!! Markdown::parse($message) !!}<!-- Using Markdown Package -->
</div>
我觉得我失去了一些东西,因为我在我的旧项目做相同的,并且工作正常。
答
$message variable is not available in markdown messages.
来源:https://laravel.com/docs/5.6/mail#writing-mailables
我想这是因为我的$ ssage代表Illuminate \ Mail \ Mailable实例本身。
请阅读[在什么情况下,我可以添加“紧急”或其他类似的短语到我的问题,以获得更快的答案?](/ meta.stackoverflow.com/q/326569) - 摘要是,这不是解决志愿者问题的理想方式,而且可能对获得答案起反作用。请不要将这添加到您的问题。 – halfer