0

I tried to to send email to admin when user register to my application

I tried these code :

$admin = Admin::where('is_admin', 3)->get();

Mail::send('emails.notfyNewUser', $data  ,  function ($message) use($admin) {

  $message->from('test@test.org','test');

  $message->to($admin->email);

  $message->subject('test');

});

And got this error :

Property [email] does not exist on this collection instance.

And this is my collection result via dd for $admin : Image

  • Possible duplicate of [Property \[title\] does not exist on this collection instance](https://stackoverflow.com/questions/41366092/property-title-does-not-exist-on-this-collection-instance) Please read here: [Why not upload images of code when asking a question](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-on-so-when-asking-a-question). – dparoli Sep 03 '19 at 19:43

1 Answers1

1

The problem is that you have 2 admins inside your collection, and the property admin is within each of those models.

You can solve it by changing your query, for something like this:

$admin = Admin::where('is_admin', 3)->first();

Or, if you want to send an email for both admins, use a foreach loop:

foreach($admin as $a) {
    Mail::send('emails.notfyNewUser', $data  ,  function ($message) use($a) {

    $message->from('test@test.org','test');

    $message->to($a->email);

    $message->subject('test');

    });
}

Hope it helps.

Mateus Junges
  • 2,559
  • 1
  • 12
  • 24