Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11.x] Add pairs method to Number #9742

Merged
merged 8 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ Laravel includes a variety of global "helper" PHP functions. Many of these funct
[Number::forHumans](#method-number-for-humans)
[Number::format](#method-number-format)
[Number::ordinal](#method-number-ordinal)
[Number::pairs](#method-number-pairs)
[Number::percentage](#method-number-percentage)
[Number::spell](#method-number-spell)
[Number::useLocale](#method-number-use-locale)
Expand Down Expand Up @@ -1308,6 +1309,23 @@ The `Number::ordinal` method returns a number's ordinal representation:

// 21st

<a name="method-number-pairs"></a>
#### `Number::pairs()` {.collection-method}

The `Number::pairs` method generates an array of number pairs (sub-ranges) based on a specified range and step value. This method can be useful for dividing a larger range of numbers into smaller, manageable sub-ranges for things like pagination or batching tasks. The `pairs` method returns an array of arrays, where each inner array represents a pair (sub-range) of numbers:

```php
use Illuminate\Support\Number;

$result = Number::pairs(25, 10);

// [[1, 10], [11, 20], [21, 25]]

$result = Number::pairs(25, 10, offset: 0);

// [[0, 10], [10, 20], [20, 25]]
```

<a name="method-number-percentage"></a>
#### `Number::percentage()` {.collection-method}

Expand Down
4 changes: 2 additions & 2 deletions precognition.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ export default function Form() {

return (
<form onSubmit={submit}>
<label for="name">Name</label>
<label htmlFor="name">Name</label>
<input
id="name"
value={form.data.name}
Expand All @@ -256,7 +256,7 @@ export default function Form() {
/>
{form.invalid('name') && <div>{form.errors.name}</div>}

<label for="email">Email</label>
<label htmlFor="email">Email</label>
<input
id="email"
value={form.data.email}
Expand Down
6 changes: 3 additions & 3 deletions queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ WHERE published = true AND (
<a name="json-where-clauses"></a>
### JSON Where Clauses

Laravel also supports querying JSON column types on databases that provide support for JSON column types. Currently, this includes MySQL 8.0+, PostgreSQL 12.0+, SQL Server 2017+, and SQLite 3.39.0+ (with the [JSON1 extension](https://www.sqlite.org/json1.html)). To query a JSON column, use the `->` operator:
Laravel also supports querying JSON column types on databases that provide support for JSON column types. Currently, this includes MariaDB 10.3+, MySQL 8.0+, PostgreSQL 12.0+, SQL Server 2017+, and SQLite 3.39.0+. To query a JSON column, use the `->` operator:

$users = DB::table('users')
->where('preferences->dining->meal', 'salad')
Expand All @@ -564,7 +564,7 @@ You may use `whereJsonContains` to query JSON arrays:
->whereJsonContains('options->languages', 'en')
->get();

If your application uses the MySQL or PostgreSQL databases, you may pass an array of values to the `whereJsonContains` method:
If your application uses the MariaDB, MySQL, or PostgreSQL databases, you may pass an array of values to the `whereJsonContains` method:

$users = DB::table('users')
->whereJsonContains('options->languages', ['en', 'de'])
Expand Down Expand Up @@ -1045,7 +1045,7 @@ DB::table('users')->updateOrInsert(
<a name="updating-json-columns"></a>
### Updating JSON Columns

When updating a JSON column, you should use `->` syntax to update the appropriate key in the JSON object. This operation is supported on MySQL 5.7+ and PostgreSQL 9.5+:
When updating a JSON column, you should use `->` syntax to update the appropriate key in the JSON object. This operation is supported on MariaDB 10.3+, MySQL 5.7+, and PostgreSQL 9.5+:

$affected = DB::table('users')
->where('id', 1)
Expand Down