Narendra Jhala
Narendra Jhala

Reputation: 113

Laravel 5.3 Query Not Return Result

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

Upvotes: 0

Views: 206

Answers (1)

Dwight
Dwight

Reputation: 12440

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').

Upvotes: 1

Related Questions