10月CMS |使用按钮发送从字段检索到的电子邮件

发布于 2025-02-10 11:13:48 字数 937 浏览 0 评论 0原文

我正在尝试动态地查找电子邮件地址(从字段中输入的内容),然后将电子邮件发送到该地址。

到目前为止,我已经能够获取按钮发送电子邮件,但无法从模型中检索地址。

示例:

控制器

public function onSend()

{  
   // Retrieve email address from Machines model in email field
   $this->vars['email'] = Machines::get('email');

   // Send to email address using partial button
   Mail::send('martin.maintenance::mail.maintenancereminder', [], function($message) {
      $message->to($this->vars['email']);
   });
}

字段(机器模型)

email:
  label: 'Email Address'
  span: auto
  type: text
  tab: Details

部分(按钮)

<button
    type="submit"
    data-request="onSend"
    class="btn btn-primary">
    Reminder
</button>

错误

很高兴提供任何其他信息。提前致谢!

I'm trying to dynamically find email address (from what has been inputted in a field), then sending out email to that address.

So far, I have been able to get the button to send emails but unable to retrieve the address from model.

Examples:

Controller

public function onSend()

{  
   // Retrieve email address from Machines model in email field
   $this->vars['email'] = Machines::get('email');

   // Send to email address using partial button
   Mail::send('martin.maintenance::mail.maintenancereminder', [], function($message) {
      $message->to($this->vars['email']);
   });
}

Field (in Machines model)

email:
  label: 'Email Address'
  span: auto
  type: text
  tab: Details

Partial (button)

<button
    type="submit"
    data-request="onSend"
    class="btn btn-primary">
    Reminder
</button>

Error
enter image description here

Happy to provide any additional info. Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

盗琴音 2025-02-17 11:13:48

我不确定您的代码中哪一部分触发了该错误,但是我怀疑这与:: get('email')返回的内容有关。

诸如此类

Illuminate\Database\Eloquent\Collection {#4744
  all: [
    App\Models\Machines {#4745
      email: "[email protected]",
    },
    App\Models\Machines {#4746
      email: "[email protected]",
    },
    // ...
  ]
}

机器:: get('email')返回机器的集合 数组/集合,执行此操作:

$this->vars['email'] = Machines::pluck('email');

Machines :: Pluck('email')返回strings之类的集合:

Illuminate\Support\Collection {#4516
  all: [
    "[email protected]",
    "[email protected]",
    // ...
  ]
}

如果您解释了阵列,则可以做:

$this->vars['email'] = Machines::pluck('email')->toArray();
/*
 * [
 *   "[email protected]",
 *   "[email protected]",
 *   // ...
 * ]
 */

也 可以: ,SideNote,Laravel中的模型名称是按照惯例单数来进行的,因此应该是Machine而不是Machines

I'm not sure what part of your code is triggering that error, but I suspect it has something to do with what ::get('email') is returning.

Machines::get('email') returns a Collection of Machines instances like this:

Illuminate\Database\Eloquent\Collection {#4744
  all: [
    App\Models\Machines {#4745
      email: "[email protected]",
    },
    App\Models\Machines {#4746
      email: "[email protected]",
    },
    // ...
  ]
}

If you want all of the email column values in an Array/Collection, do this:

$this->vars['email'] = Machines::pluck('email');

Machines::pluck('email') returns a Collection of strings like this:

Illuminate\Support\Collection {#4516
  all: [
    "[email protected]",
    "[email protected]",
    // ...
  ]
}

If you explictly need an array, you can do:

$this->vars['email'] = Machines::pluck('email')->toArray();
/*
 * [
 *   "[email protected]",
 *   "[email protected]",
 *   // ...
 * ]
 */

Also, sidenote, Model names in Laravel are by convention singular, so it should be Machine instead of Machines.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文