Monday, February 27, 2017

Eloquent doesn't produce quotes in where clause

Why doesn't this Eloquent expression produce quotes in where clause?
$q = Input::get('q');
$favorite = new Favorite;
$search   = Favorite::where('search', '=', $q)
->select('search', 'uid')->whereNotNull('search')
->where('uid', '=', Auth::user()->id)
->first();

It gives me this SQL (for example for $q = "Nike") which gives me an error because Nike is an unknown column.. But when I insert quotes manually, it works.
select `search`, `uid` from `alerts` 
where `search` = Nike 
and `search` is not null 
and `uid` = 15 limit 1



from Latest question asked on Laravel tag.


via harunB10

Advertisement