我很乐意使用查询生成器从数据库中获取用户的电子邮件地址,并向他们发送电子邮件,但到目前为止,我一直坚持这几天。Laravel 5.2将变量传递给查询生成器
公共职能postSearchAction(请求$要求){
$data = array(
'service' => $request->get('service'),
'location' => $request->get('location'),
'allProviders' => $request->get('allProviders'),
'date' => $request->get('date'),
'optional_skills' => $request->get('optional_skills'),
'landmark_homepage' => $request->get('landmark_homepage'),
'name' => Auth::user()->name,
'userEmail' => Auth::user()->email,
'requesterMobile' => Auth::user()->phone_number
);
$email = DB::table('users')->where('main_service', 'LIKE', '%'.$data['location'].'%')
->where('city_service', 'LIKE', '%'.$data['location'].'%')
->pluck('email');
To send emails
\Mail::send('auth.emails.serviceProviders', $data, function($message) use ($data)
{
$message->to($email, 'oluyemi')->subject('Test');
});
}
现在我试图用dd($邮件),但该方法返回一个空数组。 我认为值得一提的是,我一旦将查询生成器中的变量更改为期望值,一切正常。
有人应该请帮忙,不知道什么是做错了。我真的需要使用这些变量。
感谢您的帮助。
你确定'$ data ['location']'有一个值吗?有没有错误? –
@timenomad感谢您的回复.....是的,如果我做dd($ data ['location'])它会返回值。 dd($ email)返回[] – yemiwebby
$ email = DB :: table('users') - > where('main_service','LIKE','%'。$ data ['service']。'%') - > where('city_service','LIKE','%'。$ data ['location']。'%') - > pluck('email'); – yemiwebby