최신판 |
당신의 편집 |
523번째 줄: |
523번째 줄: |
|
| |
|
| ===JSON Where 절=== | | ===JSON Where 절=== |
| Laravel은 JSON 컬럼 유형을 지원하는 데이터베이스에서 JSON 컬럼 유형을 쿼리하는 것을 지원합니다. 현재 MySQL 8.0+, PostgreSQL 12.0+, SQL Server 2017+, SQLite 3.39.0+ ([https://www.sqlite.org/json1.html JSON1 확장] 포함)이 이에 해당합니다. JSON 컬럼을 쿼리하려면 <code>-></code> 연산자를 사용하세요:
| |
|
| |
| <syntaxhighlight lang='php'>
| |
| $users = DB::table('users')
| |
| ->where('preferences->dining->meal', 'salad')
| |
| ->get();
| |
| </syntaxhighlight>
| |
|
| |
| JSON 배열을 쿼리하려면 <code>whereJsonContains</code>를 사용할 수 있습니다:
| |
|
| |
| <syntaxhighlight lang='php'>
| |
| $users = DB::table('users')
| |
| ->whereJsonContains('options->languages', 'en')
| |
| ->get();
| |
| </syntaxhighlight>
| |
|
| |
| MySQL 또는 PostgreSQL 데이터베이스를 사용하는 경우, <code>whereJsonContains</code> 메소드에 값을 배열로 전달할 수 있습니다:
| |
|
| |
| <syntaxhighlight lang='php'>
| |
| $users = DB::table('users')
| |
| ->whereJsonContains('options->languages', ['en', 'de'])
| |
| ->get();
| |
| </syntaxhighlight>
| |
|
| |
| JSON 배열의 길이를 기준으로 쿼리하려면 <code>whereJsonLength</code> 메소드를 사용할 수 있습니다:
| |
|
| |
| <syntaxhighlight lang='php'>
| |
| $users = DB::table('users')
| |
| ->whereJsonLength('options->languages', 0)
| |
| ->get();
| |
|
| |
| $users = DB::table('users')
| |
| ->whereJsonLength('options->languages', '>', 1)
| |
| ->get();
| |
| </syntaxhighlight>
| |
|
| |
| ===추가 Where 절=== | | ===추가 Where 절=== |
| ;whereBetween / orWhereBetween | | ;whereBetween / orWhereBetween |