Home > Net >  I want to write this MySql Query in Laravel Controller
I want to write this MySql Query in Laravel Controller

Time:06-13

SELECT user_matches.*
FROM users u
JOIN user_matches
    ON u.id = user_matches.user_id AND 
        FIND_IN_SET(
            user_matches.to_user_id,
            (
                SELECT GROUP_CONCAT(users.id) FROM `users`
            )
        );

CodePudding user response:

Do it with

\Illuminate\Support\Facades\DB::select('') 

to write you raw query .

CodePudding user response:

What about this?

$users = \Illuminate\Support\Facades\DB::select(<<<SQL
SELECT user_matches.*
FROM users u
JOIN user_matches
    ON u.id = user_matches.user_id AND 
        FIND_IN_SET(
            user_matches.to_user_id,
            (
                SELECT GROUP_CONCAT(users.id) FROM `users`
            )
        );
SQL
);
  • Related