[英]can't access object laravel 5.3
I am using laravle 5.3 mailables for sending emails.I want to pass data to view via with method. 我正在使用laravle 5.3 mailables发送电子邮件。我想通过with方法传递数据以进行查看。
I have create a mailable MytestMail.php 我创建了一个可邮寄的MytestMail.php
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
class MytestMail extends Mailable {
public $dataArray;
use Queueable,
SerializesModels;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($dataArray) {
$this->dataArray= $dataArray;
//
}
/**
* Build the message.
*
* @return $this
*/
public function build() {
$address = 'test@gmail.com';
$name = 'asasa';
$subject = 'sasasasub';
return $this->view('emails.myTestMail')
->from($address, $name)
->cc($address, $name)
->bcc($address, $name)
->replyTo($address, $name)
->subject($subject)
->with([
'name' => $this->dataArray->name,
'password' => $this->dataArray->password,
'E_id' => $this->dataArray->E_id,
'email' => $this->dataArray->email,
]);
;
}
}
Now i get an error 现在我得到一个错误
Trying to get property of non-object 试图获取非对象的属性
When i print_r $this->dataArray i got an array with values 当我print_r $ this-> dataArray我得到一个带有值的数组
Array ( [name] => sdsdsds [E_id] => 0123 [password] => sdsd [username]
=> sdsdsdsds@sgxcxcxmail.com )
Please help me...Why i get this error message? 请帮助我...为什么我收到此错误消息?
当您使用print_r时,它会告诉您->Array<- ( [name] => sdsdsds [E_id] => 0123 [password] => sdsd [username]=> sdsdsdsds@sgxcxcxmail.com )
,因此在访问时变量$dataArray
确保以数组形式访问它,例如$this->dataArray['name']
或$this->dataArray['password']
等。
The issue is here 问题在这里
'name' => $this->dataArray->name,
you are trying to access name
from $this-dataArray
even though the name
is an index of the array hence it is not a property of an object. 您正在尝试从$this-dataArray
访问name
,即使name
是数组的索引也是如此,因此它不是对象的属性。 The error message is self-explanatory. 错误消息是不言自明的。
Trying to get property of non-object 试图获取非对象的属性
What You should do instead is 您应该做的是
'name' => $this->dataArray['name'],
Same goes to other array elements mentioned in your question. 问题中提到的其他数组元素也是如此。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.