This is my original code where i display all data for team users.
$data = Teamuser::join('teams', 'teams.id', '=', 'team_user.team_id')
->join('users', 'users.id', '=', 'team_user.user_id')
->get(['users.name as username','teams.name','users.email','team_user.role','team_user.id','team_user.user_id','team_user.team_id']);
However, since im developing a search function for the table. I try adding orwhere to the function.
$data = Teamuser::join('teams', 'teams.id', '=', 'team_user.team_id')
->join('users', 'users.id', '=', 'team_user.user_id')
->get(['users.name as username','teams.name','users.email','team_user.role','team_user.id','team_user.user_id','team_user.team_id'])
->where('users.name', 'like', '%'.$request->search2.'%')
->orWhere('teams.name', 'like', '%'.$request->search2.'%')
->orWhere('team_user.role', 'like', '%'.$request->search2.'%')
->orWhere('users.email', 'like', '%'.$request->search2.'%')->paginate(5);
But the search function doesnt work, how do i format the syntax in a correct way?
2
Answers
I’m not sure you are using
get()
correctly, but i purpose you an alternative syntaxCheck if your join is correct, maybe you could use
leftJoin()
instead ofjoin()