Hello All, So I have some weirdness happening.
I'm trying to do a search on a track database that I have, but not include tracks that a user has already selected.
My Code:
//These are track_ids in my database
$selected_tracks = array(320, 350, 1320);
//Coming from my search
$term = Input::get('term'); //Daft Punk for example
//My Query
$Tracks = Track::where('title', 'LIKE', '%'.$term.'%')
->orWhere('artist', 'LIKE', '%'.$term.'%')
->whereNotIn('id', $selected_tracks)
->select('id', 'title', 'artist')
->limit(10)
->get();
//Here is the resulting SQL query
select `id`, `title`, `artist` from `tracks` where `title` LIKE '%Daft Punk%' or `artist` LIKE '%Daft Punk%' and `id` not in ('%Daft Punk%', '%Daft Punk%', '%Daft Punk%') limit 10
Very weird? Why is this query replacing my array of selected track ids with Daft Punk? if I `dd($selected_tracks); `` it will output an array list too!.
Thanks for the help!
I think this could be a larger problem. If I back track into the /vendor/laravel/framework/src/Illuminate/Database/Connection.php when it hits the run command the query and the bindings appear to be ok.
So then it gets into $callback is where the issue must be coming from.
If I print out the last query using the \DB::getQueryLog() function. I return this:
array (size=3)
'query' => string 'select * from `tracks` where `title` LIKE ? or `artist` LIKE ? and `id` not in (?, ?, ?, ?, ?) limit 10' (length=103)
'bindings' =>
array (size=7)
0 => string '%Daft Punk%' (length=11)
1 => string '%Daft Punk%' (length=11)
2 => int 338
3 => int 377
4 => int 3343
5 => int 1185
6 => int 1532
'time' => float 27.33
But in my laravel.log file it shows something different:
select * from `tracks` where `title` LIKE '%Daft Punk%' or `artist` LIKE '%Daft Punk%' and `id` not in ('%Daft Punk%', '%Daft Punk%', '%Daft Punk%', '%Daft Punk%', '%Daft Punk%') limit 10
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community