# where

Parameters below can be used to the following methods:

{% content-ref url="/pages/IcepXaP3zNv0120JT0XR" %}
[find](/projecthyper/features/quickstart/find.md)
{% endcontent-ref %}

{% content-ref url="/pages/zQkgW8aNxdeshbWLWdig" %}
[findOne](/projecthyper/features/quickstart/findone.md)
{% endcontent-ref %}

{% content-ref url="/pages/BcqtKRDeCqZefIwKRHfP" %}
[update](/projecthyper/features/quickstart/update.md)
{% endcontent-ref %}

{% content-ref url="/pages/uEdLlFyGz8o6r32KT0jr" %}
[delete](/projecthyper/features/quickstart/delete.md)
{% endcontent-ref %}

{% content-ref url="/pages/LAmaWZHfKEcHsn7sxpfN" %}
[softDelete](/projecthyper/features/quickstart/softdelete.md)
{% endcontent-ref %}

{% content-ref url="/pages/xD9cP4j5IImFZ0H4qQKJ" %}
[count](/projecthyper/features/quickstart/count.md)
{% endcontent-ref %}

{% content-ref url="/pages/KxpFV0sS6ZzcEfff5xxH" %}
[paginate](/projecthyper/features/quickstart/paginate.md)
{% endcontent-ref %}

Where conditions are flexible you may use it like these:

```php
// Inline
$db->news->find(array('id' => 1));

// Inside where object
$db->news->find(
    array(
        'where' => array(
            'id' => 1
        )
    )
);
```

**Using Primary ID:**

<pre class="language-php"><code class="lang-php">$db->{table}->{method}(1);
<strong>$db->{table}->{method}(array('id' => 1));
</strong>$db->{table}->{method}(
    array(
        'where' => array(
            'id' => 1
        )
    )
);
</code></pre>

Example:

```php
$db->news->find(1);
$db->news->find(array('id' => 1));
$db->news->find(
    array(
        'where' => array(
            'id' => 1
        )
    )
);
```

**Using other columns:**

```php
$db->{table}->{method}(array('status' => 'ACTIVE'));
```

Example:

```php
$db->news->find(array('status' => 'ACTIVE'));
$db->news->find(array(
        'status' => 'ACTIVE',
        'created_at' => '2024-12-11 00:00:00'
    )
);
$db->news->find(array(
        'where' => array(
             'status' => 'ACTIVE',
             'created_at' => '2024-12-11 00:00:00'
        )
    )
);
```

***

**Complex Conditions:**

{% hint style="info" %}
The conditions below can be wrapped inside the "**where"** object/array
{% endhint %}

This scopes the equal, like, greater than, greater than or equal, etc.

**equal (=)**

> SELECT \* FROM news WHERE id = 1

```php
$db->news->find(
    array(
        'id' => array(
            'eq' => 1
        )
    )
);
// or 
$db->news->find(array('id' => 1));
```

**in ( IN (....)  )**

> SELECT \* FROM news WHERE id in (1, 2, 3)

```php
$db->news->find(
    array(
        'id' => array(
            'in' => array(1, 2, 3)
        )
    )
);
```

**gt ( > $ )**

> SELECT \* FROM news WHERE id > 5

```php
$db->news->find(
    array(
        'id' => array(
            'gt' => 5
        )
    )
);
```

**gte ( >= $ )**

> SELECT \* FROM news WHERE id >= 5

```php
$db->news->find(
    array(
        'id' => array(
            'gte' => 5
        )
    )
);
```

**lt ( < $ )**

> SELECT \* FROM news WHERE id < 5

```php
$db->news->find(
    array(
        'id' => array(
            'lt' => 5
        )
    )
);
```

**lte ( <= $ )**

> SELECT \* FROM news WHERE id <= 5

```php
$db->news->find(
    array(
        'id' => array(
            'lte' => 5
        )
    )
);
```

**like ( LIKE '%$%' )**

> SELECT \* FROM news WHERE name like '%test%'

```php
$db->news->find(
    array(
        'id' => array(
            'like' => 'test'
        )
    )
);
```

**between ( BETWEEN $ and $ )**

> SELECT \* FROM news WHERE created\_at between '2024-01-01' and '2024-12-31'

```php
$db->news->find(
    array(
        'id' => array(
            'between' => array('2024-01-01', '2024-12-31')
        )
    )
);
```

***

**How about the or's and the and's ?**

**or**

> SELECT \* FROM news WHERE name like '%your test%' or name = 'my test'

```php
$or_condition = array(
    'name' => array(
        'or' => array(
            'like' => 'your test',
            'eq' => 'my test',
        )
    )
);
```

**and**

> SELECT \* FROM news WHERE id ≥ 1 and id <= 20

```php
$and_condition = array(
    'id' => array(
        'and' => array(
            'gte' => 1,
            'lte' => 20
        )
    )
);
// or
$and_condition = array(
    'id' => array(
        'gte' => 1,
        'lte' => 20
    )
);
```

**not\_null**

> SELECT \* FROM news WHERE name IS NOT NULL

```php
$not_null = array(
    'name' => array(
        'not_null' => true
    )
);
```

**null**

> SELECT \* FROM news WHERE name NULL

```php
$is_null = array(
    'name' => array(
        'null' => true
    )
);
```

***

**Combining Conditions**

> SELECT \* FROM news&#x20;
>
> WHERE name like '%your test%' and name = 'my test'&#x20;
>
> &#x20; and created\_at between 'date1' and 'date2'&#x20;

```php
$where = array(
    'name' => array(
        'like' => 'your test',
        'eq' => 'my test'
    ),
    'created_at' => array(
        'between' => array(
            'date1',
            'date2'
        )
    )
)
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://jls-organization-3.gitbook.io/projecthyper/features/quickstart/parameters/where.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
