我正在一个网站上工作,我在 Laravel 5.4 中创建了一个简单的联系表格
我在 SendMailable 类中使用了以下内容:
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
class SendMailable extends Mailable
{
use Queueable, SerializesModels;
public $fullname,$phone,$email,$description;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($fullname, $phone, $email,$description)
{
$this->fullname = $fullname;
$this->phone = $phone;
$this->email = $email;
$this->description = $description;
}
/**
* Build the message. THIS WILL FORMAT YOUR OUTPUT
*
* @return $this
*/
public function build()
{
return $this->view('email.posting-message')->subject('Contact Us Subject');
}
}
在控制器中,我使用以下内容:
<?php
Namespace App\Http\Controllers;
use View;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail;
use App\Http\Controllers\Controller;
use App\Mail\SendMailable;
use Illuminate\Support\Facades\Redirect;
class PostingMessageController extends Controller
{
public function showContactUs()
{
$data = [];
return View::make('emails.posting-message',$data);
}
public function doContactUs(Request $r)
{
$fullname = $r->get('fullName');
$phone = $r->get('phone');
$email = $r->get('email');
$description = $r->get('message');
Mail::to('RECEIVER_EMAIL_ADDRESS')->send(new SendMailable($fullname, $phone, $email, $description));
if (Mail::failures())
{
$message1 = " Something Went Wrong.";
}
else
{
$message2 = " Message Sent Successfully.";
}
return redirect()->route('route_name')->with([
'warning' => $message1,
'success' => $message2
]);
}
}
刀片 emails.posting-message 包含以下内容:
<div>
<p>Fullname : {{ $this->fullname }}</p>
<p>Phone No. : {{ $this->phone }}</p>
<p>Email Address : {{ $this->email }}</p>
<p>Destination : {{ $this->destination }}</p>
<p>Description : {{ $this->description }}</p>
<hr>
<p>Thank you for your Query. We'll get back to you within 24 Hours. </p>
</div>
在路线中,我使用以下内容:
Route::get('posting-message', 'PostingMessageController@showContactUs')->name('route_name');
Route::post('posting-message', 'PostingMessageController@doContactUs')->name('route_name');
问题陈述:
我现在得到的错误是Undefined property: Illuminate\View\Engines\CompilerEngine::$fullname (View: /home/vagrant/code/search/resources/views/emails/posting-message.blade.php)
我不确定为什么会得到这个错误,因为我已经定义了它。