This is what I want to execute, but it does not work:
$users = DB::table("users")
->select(array(
'users.*',
DB::raw("CONCAT (firstname, ' ', lastname) as fullName "),
))
->where("fullName", "like", $query)
->get();
I get this error, as expected:
Column not found: 1054 Unknown column 'fullName' in 'where clause'
Is there any way to make the where clause aware of fullName? I know I can do this:
$users = DB::table("users")
->select(array(
'users.*',
DB::raw("CONCAT (firstname, ' ', lastname) as fullName "),
))
->where(DB::raw("CONCAT (firstname, ' ', lastname) like ".$query))
->get();
But if I do it like that, then I need to sanitize $query, and I prefer it if the prepared statement deals with it for me as it would in the first example.
Any idea how to get around this?