0

I am a writing a query in laravel 5.3 but query not return any data

when i run query in direct in mysql then it's work

query here

return DB::table('friends')
            ->join('users', function ($join) use ($user_id){
                $join->on(function ($joinin) use ($user_id){
                    $joinin->where('friends.user_one_id', '=', 'users.id')
                        ->where('friends.user_one_id', '!=',$user_id);
                })->orwhere(function ($andwhere) use ($user_id){
                    $andwhere->where('friends.user_two_id', '=' ,'users.id')
                     ->where('friends.user_two_id', '!=' ,$user_id);
                });
            })->where('status','=','1')
            ->where(function ($query) use ($user_id){
                $query->where('user_one_id', '=', $user_id)
                    ->orwhere('user_two_id', '=', $user_id);
            })->get();

and it possible that make this query using Eloquent ORM

2
  • Is the query builder smart enough to change != to <> Commented Sep 26, 2016 at 4:56
  • Yes. Eloquent is smart enough :) Commented Sep 26, 2016 at 6:00

1 Answer 1

1

Instead of get(), try appending toSql() instead and inspect the result. This will show you the query that the query builder has built so you can compare it to the raw query you've written, and see if you can narrow down where you went wrong.

Also, that query would work fine in Eloquent, just use Friend::join... instead of DB::table('friends').

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.