Laravel 5.4 Query Builder WHERE NOT IN with multiple WHERE

时间:2017-09-07 03:18:58

标签: laravel-5.4

select users.id, users.nickname, users.comment from users 
where users.id <> '.$userId.' and users.id NOT IN
(SELECT friends.friend_id from friends WHERE friends.user_id = '.$userId.')

我已经关注了Laravel Query Builder WHERE NOT IN并转换了我的查询

 $userId = 1;
 $friend = DB::table('users')
                ->select('users.id, users.nickname, users.comment')
                ->where('users.id', '!=', $userId)
                ->whereNotIn('users.id', function($query){
                    $query->select('friends.friend_id')
                          ->from('friends')
                          ->where('friends.user_id', '=', $userId);
                })->paginate($limit);

未定义的变量:userId: - &gt; where(&#39; friends.user_id&#39;,&#39; =&#39;,$ userId);

1 个答案:

答案 0 :(得分:0)

您必须使用import java.io.FileOutputStream; import org.apache.poi.ss.usermodel.*; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFColor; import org.apache.poi.xssf.usermodel.XSSFCellStyle; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFill; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTGradientFill; public class CreateExcelCellGradientFillColor { public static void main(String[] args) throws Exception { XSSFWorkbook workbook = new XSSFWorkbook(); Sheet sheet = workbook.createSheet(); Row row = sheet.createRow(0); XSSFCellStyle cellstyle = workbook.createCellStyle(); //set pattern fill settings only to have some fill to get the fill index from it cellstyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); //get fill index used in this CellStyle int fillidx = (int)cellstyle.getCoreXf().getFillId(); //get the low level CTFill used in this CellStyle CTFill ctfill = workbook.getStylesSource().getFillAt(fillidx).getCTFill(); System.out.println(ctfill); //unset the pattern fill ctfill.unsetPatternFill(); //now low level set the gradient fill byte[] rgb1 = new byte[3]; rgb1[0] = (byte) 0; // red rgb1[1] = (byte) 0; // green rgb1[2] = (byte) 255; // blue byte[] rgb2 = new byte[3]; rgb2[0] = (byte) 255; // red rgb2[1] = (byte) 255; // green rgb2[2] = (byte) 255; // blue CTGradientFill ctgradientfill = ctfill.addNewGradientFill(); ctgradientfill.setDegree(90.0); ctgradientfill.addNewStop().setPosition(0.0); ctgradientfill.getStopArray(0).addNewColor().setRgb(rgb1); ctgradientfill.addNewStop().setPosition(0.5); ctgradientfill.getStopArray(1).addNewColor().setRgb(rgb2); ctgradientfill.addNewStop().setPosition(1.0); ctgradientfill.getStopArray(2).addNewColor().setRgb(rgb1); System.out.println(ctfill); Cell cell = row.createCell(0); cell.setCellValue(""); cell.setCellStyle(cellstyle); workbook.write(new FileOutputStream("CreateExcelCellGradientFillColor.xlsx")); workbook.close(); } } 将变量传递给匿名函数。

use