Skip to content

Commit 27cec6b

Browse files
committed
Merge branch '10.x'
2 parents e6f79e1 + 4c5d4d5 commit 27cec6b

File tree

11 files changed

+116
-13
lines changed

11 files changed

+116
-13
lines changed

src/Illuminate/Bus/DatabaseBatchRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ protected function unserialize($serialized)
342342

343343
try {
344344
return unserialize($serialized);
345-
} catch (ModelNotFoundException $e) {
345+
} catch (ModelNotFoundException) {
346346
return [];
347347
}
348348
}

src/Illuminate/Database/Eloquent/Builder.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ public function createOrFirst(array $attributes = [], array $values = [])
581581
{
582582
try {
583583
return $this->withSavepointIfNeeded(fn () => $this->create(array_merge($attributes, $values)));
584-
} catch (UniqueConstraintViolationException $exception) {
584+
} catch (UniqueConstraintViolationException) {
585585
return $this->useWritePdo()->where($attributes)->first();
586586
}
587587
}
@@ -595,8 +595,10 @@ public function createOrFirst(array $attributes = [], array $values = [])
595595
*/
596596
public function updateOrCreate(array $attributes, array $values = [])
597597
{
598-
return tap($this->firstOrNew($attributes), function ($instance) use ($values) {
599-
$instance->fill($values)->save();
598+
return tap($this->firstOrCreate($attributes, $values), function ($instance) use ($values) {
599+
if (! $instance->wasRecentlyCreated) {
600+
$instance->fill($values)->save();
601+
}
600602
});
601603
}
602604

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ public function firstOrCreate(array $attributes = [], array $values = [], array
626626
} else {
627627
try {
628628
$this->getQuery()->withSavepointIfNeeded(fn () => $this->attach($instance, $joining, $touch));
629-
} catch (UniqueConstraintViolationException $exception) {
629+
} catch (UniqueConstraintViolationException) {
630630
// Nothing to do, the model was already attached...
631631
}
632632
}
@@ -656,7 +656,7 @@ public function createOrFirst(array $attributes = [], array $values = [], array
656656
return tap($this->related->where($attributes)->first(), function ($instance) use ($joining, $touch) {
657657
$this->getQuery()->withSavepointIfNeeded(fn () => $this->attach($instance, $joining, $touch));
658658
});
659-
} catch (UniqueConstraintViolationException $exception) {
659+
} catch (UniqueConstraintViolationException) {
660660
return (clone $this)->useWritePdo()->where($attributes)->first();
661661
}
662662
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ public function createOrFirst(array $attributes = [], array $values = [])
253253
{
254254
try {
255255
return $this->getQuery()->withSavepointIfNeeded(fn () => $this->create(array_merge($attributes, $values)));
256-
} catch (UniqueConstraintViolationException $exception) {
256+
} catch (UniqueConstraintViolationException) {
257257
return $this->useWritePdo()->where($attributes)->first();
258258
}
259259
}

src/Illuminate/Foundation/Exceptions/Handler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ protected function reportThrowable(Throwable $e): void
273273

274274
try {
275275
$logger = $this->container->make(LoggerInterface::class);
276-
} catch (Exception $ex) {
276+
} catch (Exception) {
277277
throw $e;
278278
}
279279

@@ -370,7 +370,7 @@ protected function context()
370370
return array_filter([
371371
'userId' => Auth::id(),
372372
]);
373-
} catch (Throwable $e) {
373+
} catch (Throwable) {
374374
return [];
375375
}
376376
}

src/Illuminate/Routing/CompiledRouteCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public function match(Request $request)
121121
if ($result = $matcher->matchRequest($trimmedRequest)) {
122122
$route = $this->getByName($result['_route']);
123123
}
124-
} catch (ResourceNotFoundException|MethodNotAllowedException $e) {
124+
} catch (ResourceNotFoundException|MethodNotAllowedException) {
125125
try {
126126
return $this->routes->match($request);
127127
} catch (NotFoundHttpException) {

src/Illuminate/Validation/Validator.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,6 @@ public function passes()
437437
$this->validateAttribute($attribute, $rule);
438438

439439
if ($this->shouldBeExcluded($attribute)) {
440-
$this->removeAttribute($attribute);
441-
442440
break;
443441
}
444442

@@ -448,6 +446,12 @@ public function passes()
448446
}
449447
}
450448

449+
foreach ($this->rules as $attribute => $rules) {
450+
if ($this->shouldBeExcluded($attribute)) {
451+
$this->removeAttribute($attribute);
452+
}
453+
}
454+
451455
// Here we will spin through all of the "after" hooks on this validator and
452456
// fire them off. This gives the callbacks a chance to perform all kinds
453457
// of other validation that needs to get wrapped up in this operation.

src/Illuminate/View/Compilers/ComponentTagCompiler.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ protected function compileOpeningTags(string $value)
127127
(\:\\\$)(\w+)
128128
)
129129
|
130+
(?:
131+
(![\w]+)
132+
)
133+
|
130134
(?:
131135
[\w\-:.@%]+
132136
(
@@ -192,6 +196,10 @@ protected function compileSelfClosingTags(string $value)
192196
(\:\\\$)(\w+)
193197
)
194198
|
199+
(?:
200+
(![\w]+)
201+
)
202+
|
195203
(?:
196204
[\w\-:.@%]+
197205
(
@@ -582,6 +590,7 @@ public function compileSlots(string $value)
582590
protected function getAttributesFromAttributeString(string $attributeString)
583591
{
584592
$attributeString = $this->parseShortAttributeSyntax($attributeString);
593+
$attributeString = $this->parseShortFalseSyntax($attributeString);
585594
$attributeString = $this->parseAttributeBag($attributeString);
586595
$attributeString = $this->parseComponentTagClassStatements($attributeString);
587596
$attributeString = $this->parseComponentTagStyleStatements($attributeString);
@@ -650,6 +659,21 @@ protected function parseShortAttributeSyntax(string $value)
650659
}, $value);
651660
}
652661

662+
/**
663+
* Parses a short false syntax like !required into a fully-qualified syntax like :required="false".
664+
*
665+
* @param string $value
666+
* @return string
667+
*/
668+
protected function parseShortFalseSyntax(string $value)
669+
{
670+
$pattern = "/\s!(\w+)/x";
671+
672+
return preg_replace_callback($pattern, function (array $matches) {
673+
return " :{$matches[1]}=\"false\"";
674+
}, $value);
675+
}
676+
653677
/**
654678
* Parse the attribute bag in a given attribute string into its fully-qualified syntax.
655679
*

tests/Database/DatabaseEloquentIntegrationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1460,7 +1460,7 @@ public function testNestedTransactionsUsingSaveOrFailWillSucceed()
14601460
try {
14611461
$user->email = '[email protected]';
14621462
$user->saveOrFail();
1463-
} catch (Exception $e) {
1463+
} catch (Exception) {
14641464
// ignore the exception
14651465
}
14661466

tests/Validation/ValidationValidatorTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8257,6 +8257,39 @@ public function testExclude($rules, $data, $expectedValidatedData)
82578257
$this->assertSame($expectedValidatedData, $validator->validated());
82588258
}
82598259

8260+
public function testExcludeBeforeADependentRule()
8261+
{
8262+
$validator = new Validator(
8263+
$this->getIlluminateArrayTranslator(),
8264+
[
8265+
'profile_id' => null,
8266+
'type' => 'denied',
8267+
],
8268+
[
8269+
'type' => ['required', 'string', 'exclude'],
8270+
'profile_id' => ['nullable', 'required_if:type,profile', 'integer'],
8271+
],
8272+
);
8273+
8274+
$this->assertTrue($validator->passes());
8275+
$this->assertSame(['profile_id' => null], $validator->validated());
8276+
8277+
$validator = new Validator(
8278+
$this->getIlluminateArrayTranslator(),
8279+
[
8280+
'profile_id' => null,
8281+
'type' => 'profile',
8282+
],
8283+
[
8284+
'type' => ['required', 'string', 'exclude'],
8285+
'profile_id' => ['nullable', 'required_if:type,profile', 'integer'],
8286+
],
8287+
);
8288+
8289+
$this->assertFalse($validator->passes());
8290+
$this->assertSame(['profile_id' => ['validation.required_if']], $validator->getMessageBag()->getMessages());
8291+
}
8292+
82608293
public function testExcludingArrays()
82618294
{
82628295
$validator = new Validator(

0 commit comments

Comments
 (0)