nhayder
122
2
Laravel

contact us from error "Trying to get property of non-object" for event listner

Posted 1 month ago by nhayder

i have a contact us from that triggers an event to send the email, i'm getting this error when i attempt to submit the email from the event listener


"Trying to get property of non-object"

this is my event listner

class DiliverContactFormEmailListner
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param  NewContactFormEmailStoredEvent  $event
     * @return void
     */
    public function handle(NewContactFormEmailStoredEvent $event)
    {   
        Mail::to($event->contact->email)->send(new SendContactFormEmailToDestination());
    }
}

the $contact array is passed by the main event like this

class NewContactFormEmailStoredEvent 
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public $contact;

    public function __construct($contact)
    {
        $this->$contact = $contact;
    }

}

this is what i have on the contact object

{
    "name":"News","email":"[email protected]","phone":"+97431313270","message":"this is the message","status":"new","updated_at":"2019-05-20 15:06:06","created_at":"2019-05-20 15:06:06","id":27}

any ideas ???

Please sign in or create an account to participate in this conversation.