我有一个问题!这是我的代码:
public static function getMessages($threader_id){
$messages = DB::table('messages_messages')
->join('messages_participants', function ($join) {
$join->on('messages_participants.id_message', '=', 'messages_messages.id')
->where('messages_participants.id_threader', '=', $threader_id);
})
->get();
return $messages;
}
我得到错误: undefined variable :threader_id
不知道为什么,因为当我尝试 return $threader_id;
时,它会返回值。
任何想法?谢谢
最佳答案
正确的做法:
$messages = DB::table('messages_messages')
->join('messages_participants', function ($join) use ($threader_id) {
$join->on('messages_participants.id_message', '=', 'messages_messages.id')
->where('messages_participants.id_threader',$threader_id);
})
->select('messages_messages.*')
->get();
关于QueryBuilder 的 Mysql JOIN 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41716474/