Reputation: 2420
i'm trying to run this query but it doesn't find events.id, it actually returns the string "events.id".
$events = \DB::select(\DB::raw("select 'events.id', `publish_date`, `event_name`, `information`, `latitude`, `longitude`, 111.045 * DEGREES(ACOS(COS(RADIANS(?))
* COS(RADIANS(`latitude`))
* COS(RADIANS(`longitude`) - RADIANS(?))
+ SIN(RADIANS(?))
* SIN(RADIANS(`latitude`))))
AS `distance_in_km`
FROM `events` as `tbl`
where (`publish_date` between ? and ?)
and (`event_name` like ? or `information` like ?)
and (`paid` = 1)
having (`distance_in_km` <= ?)
ORDER BY `distance_in_km` ASC
LIMIT ?,?"), array($lat, $lng, $lat, $date_from, $date_to, $search_term, $search_term, $distance, $page, intval($page)+20));
This is the response when i run
"return dd($events)"
array:14 [▼
0 => {#221 ▼
+"events.id": "events.id"
+"publish_date": "2017-05-31"
+"event_name": "asdfasdfas"
+"information": "sdfgsdfgs"
+"latitude": 34.6921597
+"longitude": 5.0225571
+"distance_in_km": 1.4213115203631
}
1 => {#93 ▶}
2 => {#225 ▶}
3 => {#222 ▶}
4 => {#224 ▶}
5 => {#226 ▶}
6 => {#227 ▶}
7 => {#228 ▶}
8 => {#229 ▶}
9 => {#230 ▶}
10 => {#231 ▶}
11 => {#232 ▶}
12 => {#233 ▶}
13 => {#234 ▶}
]
(i need to specify the table name because the actual query is a bit different with an inner join)
Upvotes: 0
Views: 57
Reputation: 57141
Your using the wrong quotes round events.id...
$events = \DB::select(\DB::raw("select `events.id`, `publish_date`,
You were selecting the literal 'events.id'.
Upvotes: 1