'Trying to send data from query to another function
first i have two problem here the first problem when i run this query it gives me this Error //ERROR
SQLSTATE[42S22]: Column not found: 1054 Unknown column '3909.6209753917' in 'on clause' (SQL: select `users`.*, `user_data`.`avatar` from `users` inner join `user_data` on `user_data`.`user_id` = `users`.`id` and (`user_data`.`city` LIKE %tripoli% and `user_data`.`address` LIKE %ain zara% and `users`.`is_admin` is null and `users`.`is_store` is null and `user_data`.`active` = 1 and `user_data`.`anyOrders` = 1 and `3909`.`6209753917` <= 3))
second Problem in where([]) i try to call a function and i send with function pramters but first two paramter go as string i'm trying to send data from user_data Table look here
where([
['user_data.city','LIKE', '%' . $store->city . '%'],
...
[$this-**>haversineGreatCircleDistance('user_data.lat','user_data.lon',$store->lat,$store->lon), '<=', '3']
]**);
here is complete function
public function searchNearUsers($id) {
$store = storeData::where('store_id',auth()->user()->id)->first();
$users = User::join('user_data', function ($join) use ($store) {
$join->on('user_data.user_id', '=', 'users.id')->where([
['user_data.city','LIKE', '%' . $store->city . '%'],
['user_data.address','LIKE', '%' . $store->address . '%'],
['users.is_admin', '=', NULL],
['users.is_store', '=', NULL],
['user_data.active', '=', 1],
['user_data.anyOrders', '=', 1],
[$this->haversineGreatCircleDistance('user_data.lat','user_data.lon',$store->lat,$store->lon), '<=', '3']
]);
})->select('users.*', 'user_data.avatar')
->get();
dd($users);
return redirect()->back();
}
Solution 1:[1]
Find below code Need '%abc%' single quote "'" for like query
public function searchNearUsers($id) {
$store = storeData::where('store_id',auth()->user()->id)->first();
$users = User::join('user_data', function ($join) use ($store) {
$join->on('user_data.user_id', '=', 'users.id')->where([
['user_data.city','LIKE', "'%" . $store->city . "%'"],
['user_data.address','LIKE', "'%" . $store->address . "%'"],
['users.is_admin', '=', NULL],
['users.is_store', '=', NULL],
['user_data.active', '=', 1],
['user_data.anyOrders', '=', 1],
[$this->haversineGreatCircleDistance('user_data.lat','user_data.lon',$store->lat,$store->lon), '<=', '3']
]);
})->select('users.*', 'user_data.avatar')
->get();
dd($users);
return redirect()->back();
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Paresh |
