$rooms3 = Room::join("notifications", "notifications.room_id", "rooms.id")
->where('rooms.user_id', Auth::user()->id)
->join("watt_histories", "watt_histories.notification_id", "notifications.id")
->where('notifications.id', 'watt_histories.notification_id')
->latest('watt_histories.created_at')
->first();
如果查询运行良好,则返回的值不为空
如果您打算比较表之间的 ID,则可能应该是 where('notifications.id', '=', 'watt_histories.notification_id') 或类似的,假设 notification.id 和 watt_histories.notification_id 是需要匹配即可查询成功。
$rooms3 = Room::join("notifications", "notifications.room_id", "rooms.id")
->where('rooms.user_id', Auth::user()->id)
->join("watt_histories", "watt_histories.notification_id", "notifications.id")
->where('notifications.id', '=', 'watt_histories.notification_id') // Corrected the comparison here
->latest('watt_histories.created_at')
->first();