是否可以在 Eloquent 中执行类似的操作?
SELECT (SELECT `name` from `players` WHERE `player_id`=`id`) AS `name`, `value` FROM `player_skills` WHERE `skillid`=0
这看起来只是一个简单的关系,所以你可以这样做:
PlayerSkill::with('Player')->where('skillid',0)->get();
您可以像这样简单地运行您的查询
DB::raw('SELECT (SELECT `name` from `players` WHERE `player_id`=`id`) AS `name`, `value` FROM `player_skills` WHERE `skillid`=0');
或者
DB::statement('SELECT (SELECT `name` from `players` WHERE `player_id`=`id`) AS `name`, `value` FROM `player_skills` WHERE `skillid`=0');
或者
DB::select('SELECT (SELECT `name` from `players` WHERE `player_id` = ?) AS `name`, `value` FROM `player_skills` WHERE `skillid`= ?', array('id', 0));
祝你好运:)