[英]Laravel 5.2 passing variable to query builder
I will love to use query builder to obtain the email address of users from the database and send emails to them all, but so far i have been stuck on this for days now. 我将很乐意使用查询生成器从数据库中获取用户的电子邮件地址,并将电子邮件发送给所有用户,但是到目前为止,我已经被困了好几天了。
public function postSearchAction(Request $request){ 公共功能postSearchAction(Request $ request){
$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');
});
}
Now i have tried to use dd($mail) but the method returned an empty array. 现在,我尝试使用dd($ mail),但该方法返回了一个空数组。 I think its worth mentioning that i once i change the variable within the query builder to the expected value, everything works fine.
我认为值得一提的是,一旦我将查询生成器中的变量更改为期望值,一切都会正常进行。
Someone should please help, dont know what am doing wrong. 有人应该帮忙,不知道做错了什么。 I really need to use the variables.
我真的需要使用变量。
Thanks for your help. 谢谢你的帮助。
Please show us the raw SQL query so we can see what's wrong. 请向我们展示原始的SQL查询,以便我们了解问题所在。
After the $email query, put: 在$ email查询之后,输入:
DB::enableQueryLog();
dd(DB::getQueryLog());
It will be the last item. 这将是最后一项。
OR 要么
Add ->toSql()
instead of ->pluck()
and dd() it. 添加
->toSql()
而不是->toSql()
->pluck()
和dd()。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.