Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

tanveerkhanwd's avatar

How to run this raw query in laravel

//I am just trying to use this query in my controller:

SELECT *,(select gaw.weight FROM game_activity_wets gaw WHERE gaw.creator_id=game_activity_wets.creator_id AND gaw.type=0 AND gaw.game_id=game_activity_wets.game_id) as startweight FROM `game_activity_wets` WHERE game_id=37 and type=2 GROUP BY creator_id
0 likes
2 replies
gopalsharma's avatar
Level 1

Please try below query , it's working fine

$aGameActivity = GameActivityWet::select(['*',\DB::raw('(select gaw.weight FROM game_activity_wets gaw WHERE gaw.creator_id=game_activity_wets.creator_id AND gaw.type=0 AND gaw.game_id=game_activity_wets.game_id) as start_weight')])
                    
                ->where('type','=',2)
                ->where('game_id','=',37)
                ->groupBy('creator_id')
                ->get();

1 like

Please or to participate in this conversation.