Unfortunately the Laravel query builder seems not in a good mood!
Here is my table structure:
Table user
structure
ID, USERNAME, NAME, USER_ROLE_MODULE_ID
Table user_role_module
structure
ID, NAME
And this is my query builder statement
DB::table('user')
->leftJoin('user_role_module', 'user.user_role_module_id', '=', 'user_role_module.id')
->select('user.*', 'user_role_module.name as user_role')
->where("name LIKE '%Jhon%' ") "or other example" ->where("user_role LIKE '%admin%' ")
->paginate(10);
Goal:
I just want to get all data from user
+ user role name from user_role_module
AND also applies in WHERE statement so I can use it for search feature.
I am getting result from WHERE statement without specifying table name. because it already stated which table and column to select from SELECT statement.
The problem:
if I search for name, it return error ambiguous column //Laravel is confusing whether taking
name
from user table or user_role_module table!if I search for user_role, then the column doesn't exist
Why is it? What is the solution?