我想知道如何使用Laravel创建Where All子句 我正在尝试检查用户看到的剧集是否都是剧集的剧集。
我正在使用WhereIn子句,但如果我看到一个系列剧集,我会返回结果。
$ alleps获得该系列的所有剧集 $ seriessaw获取用户看到的所有剧集
感谢您的回答!
$alleps = DB::table('episodes')
->select('episodes.id as ep_id')
->join('seasonsepisodes', 'episodes.id', '=', 'seasonsepisodes.episode_id')
->join('seriesseasons', 'seasonsepisodes.season_id', '=', 'seriesseasons.season_id')
->where('seriesseasons.series_id', '=', $id);
$seriesSaw = DB::table('usersepisodes')
->select('usersepisodes.episode_id as ep_id')
->where('usersepisodes.user_id', '=', Auth::user()->id)
->whereIn('usersepisodes.episode_id', $alleps)
->get();
答案 0 :(得分:1)
我认为你需要设置一个having
条款,如果记录的数量与剧集数量相同,则会强制记录返回。
$seriesSaw = DB::table('usersepisodes')
->select('usersepisodes.episode_id as ep_id')
->where('usersepisodes.user_id', '=', Auth::user()->id)
->whereIn('usersepisodes.episode_id', $alleps)
->having(\DB::raw('count(*)'), count($alleps))
->get();
但是,您应该注意,如果在userepisodes
表中有任何重复的可能性,这可能会中断。
答案 1 :(得分:0)
使用 import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.logging.Level;
import java.util.logging.Logger;
public class SlotMachineGUI extends JFrame {
private JLabel titleLabel;
private JLabel pcnameLabel;
private JLabel symLbl;
private JLabel symLb2;
private JLabel symLb3;
private JLabel creditTxtLbl;
private JLabel creditValLbl;
private JLabel betTxtLbl;
private JLabel betValLbl;
private JLabel winsTxtLbl;
private JLabel winsValLbl;
private JLabel lossValLbl;
private JLabel lossTxtLbl;
private JButton spinBtn;
private JButton resetBtn;
private JButton addCoinBtn;
private JButton betOneBtn;
private JButton betMaxBtn;
private JButton startBtn;
private JPanel pcPanel;
private JPanel btnPanel;
private JPanel mainBtnPanel;
private JPanel detailPanel;
private JPanel mainPanel;
private JPanel namePanel;
private int count = 0;
private int creditV = 10;
private final int maxCredit = 3;
private int picVal1 = 0;
private int picVal2 = 0;
private int picVal3 = 0;
private int wonCredit = 0;
int val1 = 0;
int val2 = 0;
int val3 = 0;
private int credit;
public SlotMachineGUI() {
setSize(800, 400);
//to title
titleLabel = new JLabel("--Slot Machine--");
titleLabel.setFont(new Font("", 2, 30));
titleLabel.setForeground(Color.decode("#FF0000"));
titleLabel.setHorizontalAlignment(JLabel.CENTER);
add("North", titleLabel);
pcPanel = new JPanel(new GridLayout(1, 3, 0, 0));
pcPanel.setBackground(Color.WHITE);
symLbl = new JLabel(new ImageIcon("src/cswrk2/clear.png"));
symLb2 = new JLabel(new ImageIcon("src/cswrk2/clear.png"));
symLb3 = new JLabel(new ImageIcon("src/cswrk2/clear.png"));
symLbl.setBorder(BorderFactory.createLineBorder(Color.black));
symLb2.setBorder(BorderFactory.createLineBorder(Color.black));
symLb3.setBorder(BorderFactory.createLineBorder(Color.black));
pcPanel.add(symLbl);
pcPanel.add(symLb2);
pcPanel.add(symLb3);
btnPanel = new JPanel(new GridLayout(2, 1, 0, 0));
btnPanel.setBackground(Color.decode("#310138"));
spinBtn = new JButton("Spin");
resetBtn = new JButton("Reset");
btnPanel.add(spinBtn);
btnPanel.add(resetBtn);
detailPanel = new JPanel(new GridLayout(2, 4, 0, 0));
detailPanel.setBackground(Color.decode("#000000"));
creditTxtLbl = new JLabel("Credit Left ");
creditTxtLbl.setFont(new Font("", 1, 14));
creditTxtLbl.setForeground(Color.white);
creditValLbl = new JLabel(String.valueOf(creditV));
creditValLbl.setFont(new Font("", 1, 14));
creditValLbl.setForeground(Color.white);
betTxtLbl = new JLabel("Bet ");
betTxtLbl.setFont(new Font("", 1, 14));
betTxtLbl.setForeground(Color.white);
betValLbl = new JLabel("0");
betValLbl.setFont(new Font("", 1, 14));
betValLbl.setForeground(Color.white);
winsTxtLbl = new JLabel("Wins ");
winsTxtLbl.setFont(new Font("", 1, 14));
winsTxtLbl.setForeground(Color.white);
winsValLbl = new JLabel("Wins Val ");
winsValLbl.setFont(new Font("", 1, 14));
winsValLbl.setForeground(Color.white);
lossTxtLbl = new JLabel("Wins ");
lossTxtLbl.setFont(new Font("", 1, 14));
lossTxtLbl.setForeground(Color.white);
lossValLbl = new JLabel("Wins Val ");
lossValLbl.setFont(new Font("", 1, 14));
lossValLbl.setForeground(Color.white);
detailPanel.add(creditTxtLbl);
detailPanel.add(creditValLbl);
detailPanel.add(betTxtLbl);
detailPanel.add(betValLbl);
detailPanel.add(winsTxtLbl);
detailPanel.add(winsValLbl);
detailPanel.add(lossTxtLbl);
detailPanel.add(lossValLbl);
mainPanel = new JPanel(new GridLayout(2, 1, 0, 0));
mainPanel.setBackground(Color.decode("#310138"));
mainPanel.add(pcPanel);
// mainPanel.add(btnPanel);
mainPanel.add(detailPanel);
add("East", btnPanel);
add("Center", mainPanel);
mainBtnPanel = new JPanel(new GridLayout(1, 4, 0, 0));
mainBtnPanel.setBackground(Color.decode("#310138"));
addCoinBtn = new JButton("Add Coin");
betOneBtn = new JButton("Bet One");
betMaxBtn = new JButton("Bet Max");
startBtn = new JButton("Starts");
mainBtnPanel.add(addCoinBtn);
mainBtnPanel.add(betOneBtn);
mainBtnPanel.add(betMaxBtn);
mainBtnPanel.add(startBtn);
add("South", mainBtnPanel);
setVisible(true);
addCoinBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
}
});
spinBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
Thread thread1 = new Thread(new Runnable() {
Reel spinner1 = new Reel();
//System.out.println(spinner1.spin());
Symbol[] url1 = spinner1.spin();
@Override
public void run() {
for (Symbol symbol : url1) {
try {
ImageIcon a = symbol.getImage();
Thread.sleep(100);
val1 = symbol.getValue();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
symLbl.setIcon(a);
}
});
} catch (InterruptedException ex) {
Logger.getLogger(SlotMachineGUI.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
});
picVal1 = val1;
System.out.println(picVal1);
Thread thread2 = new Thread(new Runnable() {
Reel spinner2 = new Reel();
//System.out.println(spinner1.spin());
Symbol[] url2 = spinner2.spin();
@Override
public void run() {
for (Symbol symbol : url2) {
try {
ImageIcon a = symbol.getImage();
Thread.sleep(100);
val2 = symbol.getValue();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
symLb2.setIcon(a);
}
});
} catch (InterruptedException ex) {
Logger.getLogger(SlotMachineGUI.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
});
picVal1 = val2;
System.out.println(picVal1);
Thread thread3 = new Thread(new Runnable() {
Reel spinner3 = new Reel();
//System.out.println(spinner1.spin());
Symbol[] url3 = spinner3.spin();
@Override
public void run() {
for (Symbol symbol : url3) {
try {
ImageIcon a = symbol.getImage();
Thread.sleep(100);
val3 = symbol.getValue();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
symLb3.setIcon(a);
}
});
} catch (InterruptedException ex) {
Logger.getLogger(SlotMachineGUI.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
});
picVal3 = val3;
System.out.println(picVal3);
System.out.println();
Thread resultThread = new Thread(new Runnable() {
@Override
public void run() {
thread1.start();
thread2.start();
thread3.start();
try {
thread1.join();
thread2.join();
thread3.join();
if (val1 == val2 && val2 == val3 && val3 == val1) {
System.out.println("samanaaaaaaai");
wonCredit = ((count) * picVal1);
creditV += wonCredit;
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
creditValLbl.setText(String.valueOf(creditV));
betValLbl.setText(String.valueOf(0));
JOptionPane.showMessageDialog(startBtn,
"You won " + wonCredit + " credits",
"!!JACKPOT!!",
JOptionPane.PLAIN_MESSAGE);
}
});
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
resultThread.start();
}
});
betOneBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
if (count < 4) {
betValLbl.setText(String.valueOf(count));
creditV--;
creditValLbl.setText(String.valueOf(creditV));
count++;
} else {
count--;
}
}
});
betMaxBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
creditV -= maxCredit;
//creditValLbl.setText(String.valueOf(creditV));
betValLbl.setText(String.valueOf(maxCredit));
}
});
startBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
}
});
}
public static void main(String[] args) {
SlotMachineGUI mainWindow = new SlotMachineGUI();
}
}
时,必须将数组作为第二个参数传递。
WhereIn