Skip to content

Commit

Permalink
Merge branch '10.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
nunomaduro committed Feb 26, 2024
2 parents 819e6e0 + 7786835 commit 39561b1
Show file tree
Hide file tree
Showing 32 changed files with 870 additions and 30 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/releases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ jobs:

- name: Cleanup release notes
run: |
sed -i '/## What'"'"'s Changed/d' ${{ steps.notes.outputs.release-notes }}
sed -i '/## New Contributors/,//d' ${{ steps.notes.outputs.release-notes }}
sed -i '/## What/d' ${{ steps.notes.outputs.release-notes }}
sed -i '/## New Contributors/,$d' ${{ steps.notes.outputs.release-notes }}
- name: Create release
uses: softprops/action-gh-release@v1
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Auth/Notifications/ResetPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ResetPassword extends Notification
/**
* The callback that should be used to build the mail message.
*
* @var (\Closure(mixed, string): \Illuminate\Notifications\Messages\MailMessage)|null
* @var (\Closure(mixed, string): \Illuminate\Notifications\Messages\MailMessage|\Illuminate\Contracts\Mail\Mailable)|null
*/
public static $toMailCallback;

Expand Down Expand Up @@ -114,7 +114,7 @@ public static function createUrlUsing($callback)
/**
* Set a callback that should be used when building the notification mail message.
*
* @param \Closure(mixed, string): \Illuminate\Notifications\Messages\MailMessage $callback
* @param \Closure(mixed, string): (\Illuminate\Notifications\Messages\MailMessage|\Illuminate\Contracts\Mail\Mailable) $callback
* @return void
*/
public static function toMailUsing($callback)
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Auth/TokenGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function user()
/**
* Get the token for the current request.
*
* @return string
* @return string|null
*/
public function getTokenForRequest()
{
Expand Down
6 changes: 3 additions & 3 deletions src/Illuminate/Bus/Batchable.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function batch()
}

if ($this->batchId) {
return Container::getInstance()->make(BatchRepository::class)->find($this->batchId);
return Container::getInstance()->make(BatchRepository::class)?->find($this->batchId);
}
}

Expand Down Expand Up @@ -74,7 +74,7 @@ public function withBatchId(string $batchId)
* @param int $failedJobs
* @param array $failedJobIds
* @param array $options
* @param \Carbon\CarbonImmutable $createdAt
* @param \Carbon\CarbonImmutable|null $createdAt
* @param \Carbon\CarbonImmutable|null $cancelledAt
* @param \Carbon\CarbonImmutable|null $finishedAt
* @return array{0: $this, 1: \Illuminate\Support\Testing\Fakes\BatchFake}
Expand All @@ -86,7 +86,7 @@ public function withFakeBatch(string $id = '',
int $failedJobs = 0,
array $failedJobIds = [],
array $options = [],
CarbonImmutable $createdAt = null,
?CarbonImmutable $createdAt = null,
?CarbonImmutable $cancelledAt = null,
?CarbonImmutable $finishedAt = null)
{
Expand Down
17 changes: 15 additions & 2 deletions src/Illuminate/Cache/RateLimiter.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,26 @@ public function tooManyAttempts($key, $maxAttempts)
}

/**
* Increment the counter for a given key for a given decay time.
* Increment (by 1) the counter for a given key for a given decay time.
*
* @param string $key
* @param int $decaySeconds
* @return int
*/
public function hit($key, $decaySeconds = 60)
{
return $this->increment($key, $decaySeconds);
}

/**
* Increment the counter for a given key for a given decay time by a given amount.
*
* @param string $key
* @param int $decaySeconds
* @param int $amount
* @return int
*/
public function increment($key, $decaySeconds = 60, $amount = 1)
{
$key = $this->cleanRateLimiterKey($key);

Expand All @@ -121,7 +134,7 @@ public function hit($key, $decaySeconds = 60)

$added = $this->cache->add($key, 0, $decaySeconds);

$hits = (int) $this->cache->increment($key);
$hits = (int) $this->cache->increment($key, $amount);

if (! $added && $hits == 1) {
$this->cache->put($key, 1, $decaySeconds);
Expand Down
2 changes: 2 additions & 0 deletions src/Illuminate/Collections/Arr.php
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,8 @@ public static function only($array, $keys)
*/
public static function select($array, $keys)
{
$keys = static::wrap($keys);

return static::map($array, function ($item) use ($keys) {
$result = [];

Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Database/Eloquent/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1456,9 +1456,9 @@ protected function groupWhereSliceForScope(QueryBuilder $query, $whereSlice)
// Here we'll check if the given subset of where clauses contains any "or"
// booleans and in this case create a nested where expression. That way
// we don't add any unnecessary nesting thus keeping the query clean.
if ($whereBooleans->contains('or')) {
if ($whereBooleans->contains(fn ($logicalOperator) => str_contains($logicalOperator, 'or'))) {
$query->wheres[] = $this->createNestedWhere(
$whereSlice, $whereBooleans->first()
$whereSlice, str_replace(' not', '', $whereBooleans->first())
);
} else {
$query->wheres = array_merge($query->wheres, $whereSlice);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ trait GuardsAttributes
/**
* The attributes that are mass assignable.
*
* @var array<string>
* @var array<int, string>
*/
protected $fillable = [];

Expand Down
10 changes: 10 additions & 0 deletions src/Illuminate/Database/Eloquent/Relations/MorphToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,16 @@ public function getMorphType()
return $this->morphType;
}

/**
* Get the fully qualified morph type for the relation.
*
* @return string
*/
public function getQualifiedMorphTypeName()
{
return $this->qualifyPivotColumn($this->morphType);
}

/**
* Get the class name of the parent model.
*
Expand Down
4 changes: 1 addition & 3 deletions src/Illuminate/Database/Eloquent/Relations/Relation.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Database\MultipleRecordsFoundException;
use Illuminate\Database\Query\Expression;
use Illuminate\Support\Traits\Conditionable;
use Illuminate\Support\Traits\ForwardsCalls;
use Illuminate\Support\Traits\Macroable;
use Illuminate\Support\Traits\Tappable;

abstract class Relation implements BuilderContract
{
use Conditionable, ForwardsCalls, Macroable, Tappable {
use ForwardsCalls, Macroable {
Macroable::__call as macroCall;
}

Expand Down
46 changes: 46 additions & 0 deletions src/Illuminate/Database/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,39 @@ public function joinSub($query, $as, $first, $operator = null, $second = null, $
return $this->join(new Expression($expression), $first, $operator, $second, $type, $where);
}

/**
* Add a lateral join clause to the query.
*
* @param \Closure|\Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder|string $query
* @param string $as
* @param string $type
* @return $this
*/
public function joinLateral($query, string $as, string $type = 'inner')
{
[$query, $bindings] = $this->createSub($query);

$expression = '('.$query.') as '.$this->grammar->wrapTable($as);

$this->addBinding($bindings, 'join');

$this->joins[] = $this->newJoinLateralClause($this, $type, new Expression($expression));

return $this;
}

/**
* Add a lateral left join to the query.
*
* @param \Closure|\Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder|string $query
* @param string $as
* @return $this
*/
public function leftJoinLateral($query, string $as)
{
return $this->joinLateral($query, $as, 'left');
}

/**
* Add a left join to the query.
*
Expand Down Expand Up @@ -733,6 +766,19 @@ protected function newJoinClause(self $parentQuery, $type, $table)
return new JoinClause($parentQuery, $type, $table);
}

/**
* Get a new join lateral clause.
*
* @param \Illuminate\Database\Query\Builder $parentQuery
* @param string $type
* @param string $table
* @return \Illuminate\Database\Query\JoinLateralClause
*/
protected function newJoinLateralClause(self $parentQuery, $type, $table)
{
return new JoinLateralClause($parentQuery, $type, $table);
}

/**
* Merge an array of where clauses and bindings.
*
Expand Down
19 changes: 19 additions & 0 deletions src/Illuminate/Database/Query/Grammars/Grammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Database\Grammar as BaseGrammar;
use Illuminate\Database\Query\Builder;
use Illuminate\Database\Query\JoinClause;
use Illuminate\Database\Query\JoinLateralClause;
use Illuminate\Support\Arr;
use RuntimeException;

Expand Down Expand Up @@ -193,10 +194,28 @@ protected function compileJoins(Builder $query, $joins)

$tableAndNestedJoins = is_null($join->joins) ? $table : '('.$table.$nestedJoins.')';

if ($join instanceof JoinLateralClause) {
return $this->compileJoinLateral($join, $tableAndNestedJoins);
}

return trim("{$join->type} join {$tableAndNestedJoins} {$this->compileWheres($join)}");
})->implode(' ');
}

/**
* Compile a "lateral join" clause.
*
* @param \Illuminate\Database\Query\JoinLateralClause $join
* @param string $expression
* @return string
*
* @throws \RuntimeException
*/
public function compileJoinLateral(JoinLateralClause $join, string $expression): string
{
throw new RuntimeException('This database engine does not support lateral joins.');
}

/**
* Compile the "where" portions of the query.
*
Expand Down
13 changes: 13 additions & 0 deletions src/Illuminate/Database/Query/Grammars/MySqlGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Illuminate\Database\Query\Grammars;

use Illuminate\Database\Query\Builder;
use Illuminate\Database\Query\JoinLateralClause;
use Illuminate\Support\Str;

class MySqlGrammar extends Grammar
Expand Down Expand Up @@ -343,6 +344,18 @@ public function compileUpsert(Builder $query, array $values, array $uniqueBy, ar
return $sql.$columns;
}

/**
* Compile a "lateral join" clause.
*
* @param \Illuminate\Database\Query\JoinLateralClause $join
* @param string $expression
* @return string
*/
public function compileJoinLateral(JoinLateralClause $join, string $expression): string
{
return trim("{$join->type} join lateral {$expression} on true");
}

/**
* Prepare a JSON column being updated using the JSON_SET function.
*
Expand Down
13 changes: 13 additions & 0 deletions src/Illuminate/Database/Query/Grammars/PostgresGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Illuminate\Database\Query\Grammars;

use Illuminate\Database\Query\Builder;
use Illuminate\Database\Query\JoinLateralClause;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;

Expand Down Expand Up @@ -409,6 +410,18 @@ public function compileUpsert(Builder $query, array $values, array $uniqueBy, ar
return $sql.$columns;
}

/**
* Compile a "lateral join" clause.
*
* @param \Illuminate\Database\Query\JoinLateralClause $join
* @param string $expression
* @return string
*/
public function compileJoinLateral(JoinLateralClause $join, string $expression): string
{
return trim("{$join->type} join lateral {$expression} on true");
}

/**
* Prepares a JSON column being updated using the JSONB_SET function.
*
Expand Down
15 changes: 15 additions & 0 deletions src/Illuminate/Database/Query/Grammars/SqlServerGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Illuminate\Database\Query\Grammars;

use Illuminate\Database\Query\Builder;
use Illuminate\Database\Query\JoinLateralClause;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;

Expand Down Expand Up @@ -460,6 +461,20 @@ public function prepareBindingsForUpdate(array $bindings, array $values)
);
}

/**
* Compile a "lateral join" clause.
*
* @param \Illuminate\Database\Query\JoinLateralClause $join
* @param string $expression
* @return string
*/
public function compileJoinLateral(JoinLateralClause $join, string $expression): string
{
$type = $join->type == 'left' ? 'outer' : 'cross';

return trim("{$type} apply {$expression}");
}

/**
* Compile the SQL statement to define a savepoint.
*
Expand Down
8 changes: 8 additions & 0 deletions src/Illuminate/Database/Query/JoinLateralClause.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Illuminate\Database\Query;

class JoinLateralClause extends JoinClause
{
//
}
14 changes: 12 additions & 2 deletions src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,21 @@ class MySqlGrammar extends Grammar
*/
public function compileCreateDatabase($name, $connection)
{
$charset = $connection->getConfig('charset');
$collation = $connection->getConfig('collation');

if (! $charset || ! $collation) {
return sprintf(
'create database %s',
$this->wrapValue($name),
);
}

return sprintf(
'create database %s default character set %s default collate %s',
$this->wrapValue($name),
$this->wrapValue($connection->getConfig('charset')),
$this->wrapValue($connection->getConfig('collation')),
$this->wrapValue($charset),
$this->wrapValue($collation),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,15 +266,17 @@ protected function whenLoaded($relationship, $value = null, $default = null)
return value($default);
}

$loadedValue = $this->resource->{$relationship};

if (func_num_args() === 1) {
return $this->resource->{$relationship};
return $loadedValue;
}

if ($this->resource->{$relationship} === null) {
if ($loadedValue === null) {
return;
}

return value($value);
return value($value, $loadedValue);
}

/**
Expand Down
Loading

0 comments on commit 39561b1

Please sign in to comment.