Skip to content

Commit 7a732d5

Browse files
committed
Merge remote-tracking branch 'upstream/12.x'
Signed-off-by: Mior Muhammad Zaki <[email protected]>
2 parents 6c26422 + 912ab40 commit 7a732d5

28 files changed

+319
-149
lines changed

.github/workflows/tests.yml

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
fail-fast: true
4141
matrix:
4242
php: [8.3, 8.4]
43-
phpunit: ['10.5.35', '11.5.3', '12.0.0']
43+
phpunit: ['10.5.35', '11.5.3', '12.0.0', '12.1.0']
4444
stability: [prefer-lowest, prefer-stable]
4545

4646
name: PHP ${{ matrix.php }} - PHPUnit ${{ matrix.phpunit }} - ${{ matrix.stability }}
@@ -64,19 +64,12 @@ jobs:
6464
- name: Set Framework version
6565
run: composer config version "13.x-dev"
6666

67-
- name: Set PHPUnit
68-
uses: nick-fields/retry@v3
69-
with:
70-
timeout_minutes: 5
71-
max_attempts: 5
72-
command: composer require phpunit/phpunit:^${{ matrix.phpunit }} --dev --no-interaction --no-update
73-
7467
- name: Install dependencies
7568
uses: nick-fields/retry@v3
7669
with:
7770
timeout_minutes: 5
7871
max_attempts: 5
79-
command: composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress
72+
command: composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress --with="phpunit/phpunit:~${{ matrix.phpunit }}"
8073

8174
- name: Execute tests
8275
run: vendor/bin/phpunit --display-deprecation ${{ matrix.stability == 'prefer-stable' && '--fail-on-deprecation' || '' }}
@@ -103,11 +96,8 @@ jobs:
10396
fail-fast: true
10497
matrix:
10598
php: [8.3, 8.4]
106-
phpunit: ['11.5.3']
99+
phpunit: ['10.5.35', '11.5.3', '12.0.0', '12.1.0']
107100
stability: [prefer-lowest, prefer-stable]
108-
exclude:
109-
- php: 8.4
110-
stability: prefer-lowest
111101

112102
name: PHP ${{ matrix.php }} - PHPUnit ${{ matrix.phpunit }} - ${{ matrix.stability }} - Windows
113103

@@ -131,20 +121,12 @@ jobs:
131121
- name: Set Framework version
132122
run: composer config version "13.x-dev"
133123

134-
- name: Set PHPUnit
135-
uses: nick-fields/retry@v3
136-
with:
137-
timeout_minutes: 5
138-
max_attempts: 5
139-
command: composer require phpunit/phpunit:^${{ matrix.phpunit }} --dev --no-interaction --no-update
140-
shell: bash
141-
142124
- name: Install dependencies
143125
uses: nick-fields/retry@v3
144126
with:
145127
timeout_minutes: 5
146128
max_attempts: 5
147-
command: composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress
129+
command: composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress --with="phpunit/phpunit:~${{ matrix.phpunit }}"
148130

149131
- name: Execute tests
150132
run: vendor/bin/phpunit

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Release Notes for 12.x
22

3-
## [Unreleased](https://github.com/laravel/framework/compare/v12.7.1...12.x)
3+
## [Unreleased](https://github.com/laravel/framework/compare/v12.7.2...12.x)
4+
5+
## [v12.7.2](https://github.com/laravel/framework/compare/v12.7.1...v12.7.2) - 2025-04-03
46

57
## [v12.7.1](https://github.com/laravel/framework/compare/v12.7.0...v12.7.1) - 2025-04-03
68

src/Illuminate/Collections/Traits/EnumeratesValues.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,19 @@ public static function times($number, ?callable $callback = null)
179179
->map($callback);
180180
}
181181

182+
/**
183+
* Create a new collection by decoding a JSON string.
184+
*
185+
* @param string $json
186+
* @param int $depth
187+
* @param int $flags
188+
* @return static<TKey, TValue>
189+
*/
190+
public static function fromJson($json, $depth = 512, $flags = 0)
191+
{
192+
return new static(json_decode($json, true, $depth, $flags));
193+
}
194+
182195
/**
183196
* Get the average value of a given key.
184197
*
@@ -1046,11 +1059,8 @@ public function __get($key)
10461059
*/
10471060
protected function getArrayableItems($items)
10481061
{
1049-
if (is_array($items)) {
1050-
return $items;
1051-
}
1052-
10531062
return match (true) {
1063+
is_array($items) => $items,
10541064
$items instanceof WeakMap => throw new InvalidArgumentException('Collections can not be created using instances of WeakMap.'),
10551065
$items instanceof Enumerable => $items->all(),
10561066
$items instanceof Arrayable => $items->toArray(),

src/Illuminate/Collections/Traits/TransformsToResourceCollection.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Illuminate\Support\Traits;
44

55
use Illuminate\Database\Eloquent\Model;
6-
use Illuminate\Http\Resources\Json\JsonResource;
76
use Illuminate\Http\Resources\Json\ResourceCollection;
87
use LogicException;
98

@@ -12,8 +11,8 @@ trait TransformsToResourceCollection
1211
/**
1312
* Create a new resource collection instance for the given resource.
1413
*
15-
* @param class-string<JsonResource>|null $resourceClass
16-
* @return ResourceCollection
14+
* @param class-string<\Illuminate\Http\Resources\Json\JsonResource>|null $resourceClass
15+
* @return \Illuminate\Http\Resources\Json\ResourceCollection
1716
*
1817
* @throws \Throwable
1918
*/
@@ -29,7 +28,7 @@ public function toResourceCollection(?string $resourceClass = null): ResourceCol
2928
/**
3029
* Guess the resource collection for the items.
3130
*
32-
* @return ResourceCollection
31+
* @return \Illuminate\Http\Resources\Json\ResourceCollection
3332
*
3433
* @throws \Throwable
3534
*/

src/Illuminate/Collections/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
}
3535
},
3636
"suggest": {
37+
"illuminate/http": "Required to convert collections to API resources (^12.0).",
3738
"symfony/var-dumper": "Required to use the dump method (^7.2)."
3839
},
3940
"config": {

src/Illuminate/Http/Resources/TransformsToResource.php renamed to src/Illuminate/Database/Eloquent/Concerns/TransformsToResource.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Illuminate\Http\Resources;
3+
namespace Illuminate\Database\Eloquent\Concerns;
44

55
use Illuminate\Http\Resources\Json\JsonResource;
66
use Illuminate\Support\Str;
@@ -11,8 +11,8 @@ trait TransformsToResource
1111
/**
1212
* Create a new resource object for the given resource.
1313
*
14-
* @param class-string<JsonResource>|null $resourceClass
15-
* @return JsonResource
14+
* @param class-string<\Illuminate\Http\Resources\Json\JsonResource>|null $resourceClass
15+
* @return \Illuminate\Http\Resources\Json\JsonResource
1616
*
1717
* @throws \Throwable
1818
*/
@@ -28,7 +28,7 @@ public function toResource(?string $resourceClass = null): JsonResource
2828
/**
2929
* Guess the resource class for the model.
3030
*
31-
* @return JsonResource
31+
* @return \Illuminate\Http\Resources\Json\JsonResource
3232
*
3333
* @throws \Throwable
3434
*/
@@ -46,7 +46,7 @@ protected function guessResource(): JsonResource
4646
/**
4747
* Guess the resource class name for the model.
4848
*
49-
* @return array<class-string<JsonResource>>
49+
* @return array<class-string<\Illuminate\Http\Resources\Json\JsonResource>>
5050
*/
5151
public static function guessResourceName(): array
5252
{

src/Illuminate/Database/Eloquent/MassPrunable.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ public function pruneAll(int $chunkSize = 1000)
2323

2424
$total = 0;
2525

26+
$softDeletable = in_array(SoftDeletes::class, class_uses_recursive(get_class($this)));
27+
2628
do {
27-
$total += $count = in_array(SoftDeletes::class, class_uses_recursive(get_class($this)))
29+
$total += $count = $softDeletable
2830
? $query->forceDelete()
2931
: $query->delete();
3032

src/Illuminate/Database/Eloquent/Model.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use Illuminate\Database\Eloquent\Relations\Concerns\AsPivot;
1818
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
1919
use Illuminate\Database\Eloquent\Relations\Pivot;
20-
use Illuminate\Http\Resources\TransformsToResource;
2120
use Illuminate\Support\Arr;
2221
use Illuminate\Support\Collection as BaseCollection;
2322
use Illuminate\Support\Str;
@@ -40,8 +39,8 @@ abstract class Model implements Arrayable, ArrayAccess, CanBeEscapedWhenCastToSt
4039
Concerns\HidesAttributes,
4140
Concerns\GuardsAttributes,
4241
Concerns\PreventsCircularRecursion,
43-
ForwardsCalls,
44-
TransformsToResource;
42+
Concerns\TransformsToResource,
43+
ForwardsCalls;
4544
/** @use HasCollection<\Illuminate\Database\Eloquent\Collection<array-key, static & self>> */
4645
use HasCollection;
4746

src/Illuminate/Database/Eloquent/Relations/HasOneOrMany.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,34 @@ public function createManyQuietly(iterable $records)
436436
return Model::withoutEvents(fn () => $this->createMany($records));
437437
}
438438

439+
/**
440+
* Create a Collection of new instances of the related model, allowing mass-assignment.
441+
*
442+
* @param iterable $records
443+
* @return \Illuminate\Database\Eloquent\Collection<int, TRelatedModel>
444+
*/
445+
public function forceCreateMany(iterable $records)
446+
{
447+
$instances = $this->related->newCollection();
448+
449+
foreach ($records as $record) {
450+
$instances->push($this->forceCreate($record));
451+
}
452+
453+
return $instances;
454+
}
455+
456+
/**
457+
* Create a Collection of new instances of the related model, allowing mass-assignment and without raising any events to the parent model.
458+
*
459+
* @param iterable $records
460+
* @return \Illuminate\Database\Eloquent\Collection<int, TRelatedModel>
461+
*/
462+
public function forceCreateManyQuietly(iterable $records)
463+
{
464+
return Model::withoutEvents(fn () => $this->forceCreateMany($records));
465+
}
466+
439467
/**
440468
* Set the foreign ID for creating a related model.
441469
*

src/Illuminate/Database/Query/Grammars/Grammar.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1203,7 +1203,7 @@ public function compileInsertOrIgnore(Builder $query, array $values)
12031203
*
12041204
* @param \Illuminate\Database\Query\Builder $query
12051205
* @param array $values
1206-
* @param string $sequence
1206+
* @param string|null $sequence
12071207
* @return string
12081208
*/
12091209
public function compileInsertGetId(Builder $query, $values, $sequence)

0 commit comments

Comments
 (0)