protected function _sendCommisionFirstOrderMail(array $data = array()) { // before send mail, insert data commision $commision = ['type' => 'credit', 'nominal' => \Config::get('thankspace.space_credit.commision'), 'keterangan' => 'Commision earned for new customer first order', 'created_at' => date('Y-m-d h:i:s'), 'updated_at' => date('Y-m-d h:i:s')]; $space = []; foreach ($data as $d) { array_push($space, array_merge(array('user_id' => $d->ref_code_user_id), $commision)); } \Space::insert($space); // send mail foreach ($data as $d) { $fullname = ucfirst($d->ref_code_firstname) . ' ' . ucfirst($d->ref_code_lastname); $to = ['email' => $d->ref_code_email, 'name' => $fullname]; $data_mail = ['name' => $fullname, 'commision' => \Config::get('thankspace.space_credit.commision')]; \Mail::send('emails.commision-first-order', $data_mail, function ($message) use($to) { $message->to($to['email'], $to['name'])->subject('[ThankSpace] Komisi order pertama dari pelanggan baru'); }); } }