Skip to content

Commit fa3fcce

Browse files
committed
Merge branch '2.x' into pr/rodrigopedra/706
2 parents e078b45 + d208951 commit fa3fcce

18 files changed

+339
-28
lines changed

.github/CODE_OF_CONDUCT.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Code of Conduct
2+
3+
The Laravel Code of Conduct can be found in the [Laravel documentation](https://laravel.com/docs/contributions#code-of-conduct).

.github/FUNDING.yml

-1
This file was deleted.

.github/PULL_REQUEST_TEMPLATE.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!--
2+
Please only send a pull request to branches which are currently supported: https://laravel.com/docs/releases#support-policy
3+
4+
If you are unsure which branch your pull request should be sent to, please read: https://laravel.com/docs/contributions#which-branch
5+
6+
Pull requests without a descriptive title, thorough description, or tests will be closed.
7+
8+
In addition, please describe the benefit to end users; the reasons it does not break any existing features; how it makes building web applications easier, etc.
9+
-->

.github/SECURITY.md

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# Security Policy
2+
3+
**PLEASE DON'T DISCLOSE SECURITY-RELATED ISSUES PUBLICLY, [SEE BELOW](#reporting-a-vulnerability).**
4+
5+
## Supported Versions
6+
7+
Only the latest major version receives security fixes.
8+
9+
## Reporting a Vulnerability
10+
11+
If you discover a security vulnerability within Laravel, please send an email to Taylor Otwell at [email protected]. All security vulnerabilities will be promptly addressed.
12+
13+
### Public PGP Key
14+
15+
```
16+
-----BEGIN PGP PUBLIC KEY BLOCK-----
17+
Version: OpenPGP v2.0.8
18+
Comment: Report Security Vulnerabilities to [email protected]
19+
20+
xsFNBFugFSQBEACxEKhIY9IoJzcouVTIYKJfWFGvwFgbRjQWBiH3QdHId5vCrbWo
21+
s2l+4Rv03gMG+yHLJ3rWElnNdRaNdQv59+lShrZF7Bvu7Zvc0mMNmFOM/mQ/K2Lt
22+
OK/8bh6iwNNbEuyOhNQlarEy/w8hF8Yf55hBeu/rajGtcyURJDloQ/vNzcx4RWGK
23+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3YFIfgmGPYbL0elvXVn7XfvwSV1mCQV5LtMbLHsFf0VsA16UsG8A/tLWtwgt
87+
0antzftRHXb+DI4qr+qEYKFkv9F3oCOXyH4QBhPA42EzKqhMXByEkEK9bu6skioL
88+
mHhDQ7yHjTWcxstqQjkUQ0T/IF9ls+Sm5u7rVXEifpyI7MCb+76kSCDawesvInKt
89+
WBGOG/qJGDlNiqBYYt2xNqzHCJoC
90+
=zXOv
91+
-----END PGP PUBLIC KEY BLOCK-----
92+
```

.github/SUPPORT.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Support Questions
2+
3+
The Laravel support guide can be found in the [Laravel documentation](https://laravel.com/docs/contributions#support-questions).
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: fix code styling
2+
3+
on: [push]
4+
5+
permissions:
6+
contents: write
7+
8+
jobs:
9+
lint:
10+
uses: laravel/.github/.github/workflows/coding-standards.yml@main
11+
with:
12+
php: "8.3"

.github/workflows/tests.yml

+6-4
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ jobs:
1313
fail-fast: true
1414
matrix:
1515
php: [8.1, 8.2, 8.3, 8.4]
16-
laravel: [10, 11]
16+
laravel: [10, 11, 12]
1717
stability: ["prefer-lowest", "prefer-stable"]
1818
exclude:
1919
- php: 8.4
2020
laravel: 10
2121
- php: 8.1
2222
laravel: 11
23+
- php: 8.1
24+
laravel: 12
2325

2426
name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} (w/ ${{ matrix.stability }})
2527
steps:
@@ -52,16 +54,16 @@ jobs:
5254
max_attempts: 5
5355
command: |
5456
composer require nesbot/carbon:^2.62.1 --dev --${{ matrix.stability }} --no-update --no-interaction
55-
if: matrix.php >= 8.2 && matrix.stability == 'prefer-lowest'
57+
if: matrix.php >= 8.2 && matrix.stability == 'prefer-lowest' && matrix.laravel < 12
5658

5759
- name: Set Minimum PHP 8.2 Versions and Laravel > 11
5860
uses: nick-fields/retry@v3
5961
with:
6062
timeout_minutes: 5
6163
max_attempts: 5
6264
command: |
63-
composer require orchestra/testbench:^9.2 --dev --${{ matrix.stability }} --no-update --no-interaction
64-
composer require phpunit/phpunit:^10.4 --dev --${{ matrix.stability }} --no-update --no-interaction
65+
composer require "orchestra/testbench:^9.2|^10.0" --dev --${{ matrix.stability }} --no-update --no-interaction
66+
composer require "phpunit/phpunit:^10.4|^11.5" --dev --${{ matrix.stability }} --no-update --no-interaction
6567
if: matrix.php >= 8.2 && matrix.stability == 'prefer-lowest' && matrix.laravel >= 11
6668

6769
- name: Set Laravel version

CHANGELOG.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
# Release Notes
22

3-
## [Unreleased](https://github.com/inertiajs/inertia-laravel/compare/v2.0.0...2.x)
3+
## [Unreleased](https://github.com/inertiajs/inertia-laravel/compare/v2.0.1...2.x)
44

55
- Nothing!
66

7+
## [v2.0.1](https://github.com/inertiajs/inertia-laravel/compare/v2.0.0...v2.0.1) - 2025-02-18
8+
9+
- Allow Laravel 12.x.
10+
11+
**Full Changelog**: https://github.com/inertiajs/inertia-laravel/compare/v2.0.0...v2.0.1
12+
713
## [v2.0.0](https://github.com/inertiajs/inertia-laravel/compare/v1.2.0...2.0.0)
814

915
- Add support for Inertia.js v2.0.0

README.md

+16
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,19 @@
1313
</p>
1414

1515
Visit [inertiajs.com](https://inertiajs.com/) to learn more.
16+
17+
## Contributing
18+
19+
Thank you for considering contributing to Inertia! You can read the contribution guide [here](.github/CONTRIBUTING.md).
20+
21+
## Code of Conduct
22+
23+
In order to ensure that the Laravel community is welcoming to all, please review and abide by the [Code of Conduct](https://laravel.com/docs/contributions#code-of-conduct).
24+
25+
## Security Vulnerabilities
26+
27+
Please review [our security policy](https://github.com/inertiajs/inertia-laravel/security/policy) on how to report security vulnerabilities.
28+
29+
## License
30+
31+
Inertia is open-sourced software licensed under the [MIT license](LICENSE.md).

composer.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@
3030
"require": {
3131
"php": "^8.1.0",
3232
"ext-json": "*",
33-
"laravel/framework": "^10.0|^11.0",
33+
"laravel/framework": "^10.0|^11.0|^12.0",
3434
"symfony/console": "^6.2|^7.0"
3535
},
3636
"require-dev": {
3737
"roave/security-advisories": "dev-master",
38-
"orchestra/testbench": "^8.0|^9.2",
38+
"orchestra/testbench": "^8.0|^9.2|^10.0",
3939
"mockery/mockery": "^1.3.3",
40-
"phpunit/phpunit": "^10.4|^11.0",
40+
"phpunit/phpunit": "^10.4|^11.5",
4141
"laravel/pint": "^1.16"
4242
},
4343
"suggest": {

src/Inertia.php

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* @method static \Inertia\DeferProp defer(callable $callback, string $group = 'default')
1919
* @method static \Inertia\AlwaysProp always(mixed $value)
2020
* @method static \Inertia\MergeProp merge(mixed $value)
21+
* @method static \Inertia\MergeProp deepMerge(mixed $value)
2122
* @method static \Inertia\Response render(string $component, array|\Illuminate\Contracts\Support\Arrayable $props = [])
2223
* @method static \Symfony\Component\HttpFoundation\Response location(string|\Symfony\Component\HttpFoundation\RedirectResponse $url)
2324
* @method static void macro(string $name, object|callable $macro)

src/MergesProps.php

+14
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,29 @@ trait MergesProps
66
{
77
protected bool $merge = false;
88

9+
protected bool $deepMerge = false;
10+
911
public function merge(): static
1012
{
1113
$this->merge = true;
1214

1315
return $this;
1416
}
1517

18+
public function deepMerge(): static
19+
{
20+
$this->deepMerge = true;
21+
22+
return $this->merge();
23+
}
24+
1625
public function shouldMerge(): bool
1726
{
1827
return $this->merge;
1928
}
29+
30+
public function shouldDeepMerge(): bool
31+
{
32+
return $this->deepMerge;
33+
}
2034
}

src/Response.php

+21-13
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ public function resolvePropertyInstances(array $props, Request $request): array
257257
DeferProp::class,
258258
AlwaysProp::class,
259259
MergeProp::class,
260-
])->first(fn ($class) => $value instanceof $class);
260+
])->first(fn($class) => $value instanceof $class);
261261

262262
if ($resolveViaApp) {
263263
$value = App::call($value);
@@ -267,8 +267,12 @@ public function resolvePropertyInstances(array $props, Request $request): array
267267
$value = $value->wait();
268268
}
269269

270-
if ($value instanceof ResourceResponse || $value instanceof JsonResource) {
271-
$value = $value->toResponse($request)->getData(true);
270+
if ($value instanceof Responsable) {
271+
$_response = $value->toResponse($request);
272+
273+
if (method_exists($_response, 'getData')) {
274+
$value = $_response->getData(true);
275+
}
272276
}
273277

274278
if (is_array($value)) {
@@ -305,18 +309,22 @@ public function resolveMergeProps(Request $request): array
305309
{
306310
$resetProps = collect(explode(',', $request->header(Header::RESET, '')));
307311
$mergeProps = collect($this->props)
308-
->filter(function ($prop) {
309-
return $prop instanceof Mergeable;
310-
})
311-
->filter(function ($prop) {
312-
return $prop->shouldMerge();
313-
})
314-
->filter(function ($prop, $key) use ($resetProps) {
315-
return ! $resetProps->contains($key);
316-
})
312+
->filter(fn($prop) => $prop instanceof Mergeable)
313+
->filter(fn($prop) => $prop->shouldMerge())
314+
->filter(fn($_, $key) => ! $resetProps->contains($key));
315+
316+
$deepMergeProps = $mergeProps
317+
->filter(fn($prop) => $prop->shouldDeepMerge())
318+
->keys();
319+
320+
$mergeProps = $mergeProps
321+
->filter(fn($prop) => ! $prop->shouldDeepMerge())
317322
->keys();
318323

319-
return $mergeProps->isNotEmpty() ? ['mergeProps' => $mergeProps->toArray()] : [];
324+
return array_filter([
325+
'mergeProps' => $mergeProps->toArray(),
326+
'deepMergeProps' => $deepMergeProps->toArray(),
327+
], fn($prop) => count($prop) > 0);
320328
}
321329

322330
public function resolveDeferredProps(Request $request): array

src/ResponseFactory.php

+19-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ class ResponseFactory
3131

3232
protected $encryptHistory;
3333

34+
/***
35+
* @param string $name The name of the root view
36+
* @return void
37+
*/
3438
public function setRootView(string $name): void
3539
{
3640
$this->rootView = $name;
@@ -64,7 +68,10 @@ public function getShared(?string $key = null, $default = null)
6468
return $this->sharedProps;
6569
}
6670

67-
public function flushShared(): void
71+
/**
72+
* @return void
73+
*/
74+
public function flushShared()
6875
{
6976
$this->sharedProps = [];
7077
}
@@ -91,6 +98,9 @@ public function clearHistory(): void
9198
session(['inertia.clear_history' => true]);
9299
}
93100

101+
/**
102+
* @param bool $encrypt
103+
*/
94104
public function encryptHistory($encrypt = true): void
95105
{
96106
$this->encryptHistory = $encrypt;
@@ -122,6 +132,14 @@ public function merge($value): MergeProp
122132
return new MergeProp($value);
123133
}
124134

135+
/**
136+
* @param mixed $value
137+
*/
138+
public function deepMerge($value): MergeProp
139+
{
140+
return (new MergeProp($value))->deepMerge();
141+
}
142+
125143
/**
126144
* @param mixed $value
127145
*/

tests/DeepMergePropTest.php

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Inertia\Tests;
4+
5+
use Illuminate\Http\Request;
6+
use Inertia\MergeProp;
7+
8+
class DeepMergePropTest extends TestCase
9+
{
10+
public function test_can_invoke_with_a_callback(): void
11+
{
12+
$mergeProp = (new MergeProp(fn () => 'A merge prop value'))->deepMerge();
13+
14+
$this->assertSame('A merge prop value', $mergeProp());
15+
}
16+
17+
public function test_can_invoke_with_a_non_callback(): void
18+
{
19+
$mergeProp = (new MergeProp(['key' => 'value']))->deepMerge();
20+
21+
$this->assertSame(['key' => 'value'], $mergeProp());
22+
}
23+
24+
public function test_can_resolve_bindings_when_invoked(): void
25+
{
26+
$mergeProp = (new MergeProp(fn (Request $request) => $request))->deepMerge();
27+
28+
$this->assertInstanceOf(Request::class, $mergeProp());
29+
}
30+
}

0 commit comments

Comments
 (0)