I'm an absolute newbie at Laravel and I'm trying to port my website into this new framework. I have this query that is giving me a headache that I'd love to convert into Eloquent format so that I can use it on my controller.
// It makes sure that you don't get as result yourself nor the people you already follow.
//I dont even know how much time I spent on this...
$query = mysqli_query($conn , " SELECT username, avatar_url FROM users
WHERE username LIKE '%".$username."%' AND username <>'".$user."'
except SELECT u.username, u.avatar_url FROM users as U JOIN followers AS F
ON U.id = F.followed_user_id
where following_user_id = ( select id from users where username='".$user."' );");
EDIT:
I've made the first part like this: DB::table("users")->where("username", "LIKE", "%$search_people%")->where("username", '<>', $user->username)->get();
and it works, but I can't handle the except part. I have a variable called $user where I store the user id so I can simplify the last WHERE.
I wrote something like this but it's totally off:
DB::table("users")->where("username", "LIKE", "%$search_people%")
->where("username", '<>', $user->username) /*next part is wrong*/
->except("$user->username", "$user->avatar_url")
->join("followers", "followers->followed_user_id", "=", "$user->id")
->where("following_user_id", "=", "$user->id");
EDIT2: I've tried to split this into two queries. Is there any way to intersect the two?
I need to have A minus B.
$result_a = DB::table("users")->where("username", "LIKE", "%$search_people%")
->where("username", '<>', $user->username);
$result_b = DB::table("users")->select("username", "avatar_url")
->join("followers", "followers.followed_user_id", "=", "users.id" )
->where("following_user_id", "=", "$user->id")->get();