Add another "full_name" column ? :)
Search first_name + last_name from one input tag
I'm displaying data related to different tables in table format in the view
-- | id | Employee Name | Project Worked on | Days| Feature Name | --
--- | txtBox | txtBox | txtBox | txtBox | txtBox | --
1. | 1 Delilah Will | Leave planner | 20 | Auto SMS
2. | 1 Delilah Will | Leave planner | 20 | Auto EMail
3. | 2 Randall Robert | Medical Store | 10 | Inventory
so each column has a input tag , which searches data from the related table ex : if i search based on project name : it will be searched in Projects table -> Project Name
When it comes to searching based on employee name there are two columns first_name and last_name in Employees table. So if i want to search based on employee name, it has to search like first_name and last_name is one single column. search can be done either on first_name or last_name or both
ex: Randall or Roberts or Randall Robert
@rhungund Just the same:
->orWhereRaw("concat(first_name, ' ', last_name) like '%?%' ");
And take my advice and wrap all your orWheres in parentheses, like this:
$query->where(function ($q) use ($columns, $value) {
foreach ($columns as $column) {
$q->orWhere($column, 'like', "%{$value}%");
}
});
Otherwise any and where clause and your whole query is messed up (SoftDelete scope being one for example).
And for your concat, this is what you need exactly:
$columns = ['col1', 'col2', ..., DB::raw("concat(first_name, ' ', last_name)")];
Please or to participate in this conversation.