How to send email to all user with condition using php laravel? -


i using php laravel v5.0. , want send email user divisi = x. query of $penerima shows 3 emails divisi = x. email sent 1 email of 3 emails. know wrong of code? thanks

if ($approve != null){         foreach ($approve $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!');             });         }     } 

if showing result of $penerima, result

illuminate\database\eloquent\collection object ( [items:protected] => array ( [0] => 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] => hend0@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] => [exists] => 1 ) [1] => 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] => 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] => 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 ) ) )

if changed get() pluck('email'), result

hsaput208@test.co

when $penerima[0], take first user. should give to method array of emails, so

$emails = user::select('email')     ->where('divisi','=', $x)     ->where('deleted','=', '0')     ->lists('email');  mail::send('mail', $data_nomor, function ($m) use ($emails) {     $m->to($emails)->subject('respond reminder!'); }); 

pluck give array of given column.

depending on laravel version, should use toarray on pluck result...


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -