I have a search input ?search=xxxx
I have two columns in my database first_name and last_name.
I want the search to work for both of them, for example if my input is John Smith
the search should be like CONCAT(first_name, last_name) ILIKE %input%
But laravel doesn't let me do it:
$customers = $customers->selectRaw("CONCAT('first_name', 'last_name') AS fullname")->where("fullname", "ilike", "%" . $text . "%");
Customers is already defined, and is an ORM object, not collection.
And the error i get for this:
SQLSTATE[42703]: Undefined column: 7 ERROR: column "fullname" does not exist LINE 1: ...) AS fullname from "people" where "type" = $1 and "fullname"... ^ (SQL: select CONCAT('first_name', 'last_name') AS fullname from "people" where "type" = customer and "fullname" ilike %fidel% order by "id" asc)
Also tried:
$customers = $customers->whereRaw("CONCAT('first_name', 'last_name')", "ilike", "%" . $text . "%");
And another error:
SQLSTATE[HY093]: Invalid parameter number: parameter was not defined (SQL: select * from "people" where "type" = customer %fidel% CONCAT('first_name', 'last_name') order by "id" asc)
$result = Customers::where(DB::raw('concat(first_name," ",last_name)') , 'LIKE' , '%keyword%')->get();let us know if it's helpful.