【发布时间】:2016-12-14 07:01:27
【问题描述】:
我正在使用 PHP Laravel v5.0。我想向所有用户发送电子邮件,其中 divisi = X。$ penerima 的查询显示 3 封电子邮件,其中 divisi = X。但电子邮件仅发送到 3 封电子邮件中的 1 封电子邮件。你知道我的代码哪里错了吗?谢谢
if ($approve != null){
foreach ($approve as $X) {
$penerima = User::select('email')
->where('divisi','=', $X)
->where('deleted','=', '0')
->get();
Mail::send('mail', $data_nomor, function ($m) use ($penerima) {
$m->to($penerima)->subject('Respond Reminder!');
});
}
}
如果我显示 $penerima 的结果,结果是
Illuminate\Database\Eloquent\Collection Object ([items:protected] => Array ([0] => App\User Object ([table:protected] => users [hidden:protected] => Array ([0] ] => 密码 [1] => remember_token ) [connection:protected] => [primaryKey:protected] => id [perPage:protected] => 15 [incrementing] => 1 [timestamps] => 1 [attributes:protected ] => Array ( [email] => hed0@gmail.com ) [original:protected] => Array ( [email] => hend0@gmail.com ) [relations:protected] => Array ( ) [visible:protected ] => Array ( ) [appends:protected] => Array ( ) [fillable:protected] => Array ( ) [guarded:protected] => Array ( [0] => * ) [dates:protected] => Array ( ) [casts:protected] => Array ( ) [touches:protected] => Array ( ) [observables:protected] => Array ( ) [with:protected] => Array ( ) [morphClass:protected] => [存在] => 1) [1] => App\User Object ([table:protected] => users [hidden:protected] => Array ([0] => password [1] => remember_token) [connection:protected ] => [主键:受保护] => id [perPage:protected] => 15 [incrementing] => 1 [timestamps] => 1 [attributes:protected] => Array ([email] => hsaput208@test.co) [original:protected] => Array ( [email] => hsaput208@test.co ) [relations:protected] => Array () [visible:protected] => Array () [appends:protected] => Array () [fillable:protected] => Array ( ) [guarded:protected] => Array ([0] => *) [dates:protected] => Array () [casts:protected] => Array () [touches:protected] => Array () [observables: protected] => Array ( ) [with:protected] => Array ( ) [morphClass:protected] => [exists] => 1 ) [2] => App\User Object ( [table:protected] => users [ hidden:protected] => Array ( [0] => password [1] => remember_token ) [connection:protected] => [primaryKey:protected] => id [perPage:protected] => 15 [incrementing] => 1 [timestamps] => 1 [attributes:protected] => Array ([email] => diae@test.co) [original:protected] => Array ([email] => diae@test.co) [relations:protected ] => 数组 ( ) [可见:受保护] => 数组( ) [appends:protected] => Array ( ) [fillable:protected] => Array ( ) [guarded:protected] => Array ( [0] => * ) [dates:protected] => Array ( ) [casts :protected] => Array ( ) [touches:protected] => Array ( ) [observables:protected] => Array ( ) [with:protected] => Array ( ) [morphClass:protected] => [exists] => 1 ) ) )
如果我把get()改成pluck('email'),结果就是
hsaput208@test.co
【问题讨论】:
-
首先获取所有电子邮件,然后在
foreach循环中发送电子邮件。现在您在 foreach 循环中收到来自查询的电子邮件,然后您将邮件发送到第一个。也应该是$penerima = User::select('email')->where(...
标签: php laravel email foreach laravel-5