Blog スタッフブログ

Laravel システム開発

[Laravel]LaravelでのorWhereの注意点

システム開発担当のTFです。

やり方

  • 普通にWhereの後にorWhereで繋ぐと繋がる
  • クロージャを用いると、orの優先ができる

サンプル

<?php
// A and b or c 
$query->where('column', '=', "A")
		->where('column2', '=', "B")
		->orWhere('column3', '=', "C");
		
// A and ( b or c )
$query->where('column', '=', "A")
		->where(function($query) {
			$query->where('column2', '=', "B")
				->orWhere('column3', '=', "C");
		});
		
?>

Warning: Undefined array key 0 in /home/fl0uhem6u4/mixltd.jp/public_html/cms/wp-content/themes/mix_theme/pagination-single.php on line 3

Warning: Attempt to read property "cat_ID" on null in /home/fl0uhem6u4/mixltd.jp/public_html/cms/wp-content/themes/mix_theme/pagination-single.php on line 3