Cannot access laravel 5.3

I am using laravle 5.3 to send emails. I want to pass data for viewing through a method.

I created a mail 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 a non-object property

When I print_r $ this-> dataArray , I got an array with values

Array ( [name] => sdsdsds [E_id] => 0123 [password] => sdsd [username]
=> sdsdsdsds@sgxcxcxmail.com )

Please help me ... Why am I getting this error message?

+4
source share
2 answers

When you type_r, it tells you the data type, which is equal ->Array<- ( [name] => sdsdsds [E_id] => 0123 [password] => sdsd [username]=> sdsdsdsds@sgxcxcxmail.com ). Therefore, when accessing a variable, $dataArraybe sure to refer to it as an array of type $this->dataArray['name']or $this->dataArray['password']etc.

+3

'name' => $this->dataArray->name,

name $this-dataArray, name , , . .

-

'name' => $this->dataArray['name'],

, .

+2

Source: https://habr.com/ru/post/1665973/


All Articles