From fb7b87c2a104439eedbc0e5f581e8a3ac4ec47e5 Mon Sep 17 00:00:00 2001 From: Jess Archer Date: Wed, 20 Jul 2022 11:08:50 +1000 Subject: [PATCH 1/3] Make model:show compatible with PHP 8.0 --- src/Illuminate/Foundation/Console/ShowModelCommand.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Illuminate/Foundation/Console/ShowModelCommand.php b/src/Illuminate/Foundation/Console/ShowModelCommand.php index 31ad7c10da45..6c65df7b5665 100644 --- a/src/Illuminate/Foundation/Console/ShowModelCommand.php +++ b/src/Illuminate/Foundation/Console/ShowModelCommand.php @@ -345,10 +345,10 @@ protected function getCastType($column, $model) */ protected function getCastsWithDates($model) { - return collect([ - ...collect($model->getDates())->flip()->map(fn () => 'datetime'), - ...$model->getCasts(), - ]); + return collect($model->getDates()) + ->flip() + ->map(fn () => 'datetime') + ->merge($model->getCasts()); } /** From dceffb5424dbcdd99700ec201edc4e5c0be74fea Mon Sep 17 00:00:00 2001 From: Jess Archer Date: Wed, 20 Jul 2022 11:12:06 +1000 Subject: [PATCH 2/3] Prevent errors with false-positive relations --- src/Illuminate/Foundation/Console/ShowModelCommand.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Foundation/Console/ShowModelCommand.php b/src/Illuminate/Foundation/Console/ShowModelCommand.php index 6c65df7b5665..4b386ea16e03 100644 --- a/src/Illuminate/Foundation/Console/ShowModelCommand.php +++ b/src/Illuminate/Foundation/Console/ShowModelCommand.php @@ -7,6 +7,7 @@ use Doctrine\DBAL\Types\DecimalType; use Illuminate\Console\Command; use Illuminate\Contracts\Container\BindingResolutionException; +use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Support\Str; use ReflectionClass; use ReflectionMethod; @@ -201,16 +202,21 @@ protected function getRelations($model) return collect($this->relationMethods) ->contains(fn ($relationMethod) => str_contains($code, '$this->'.$relationMethod.'(')); }) - ->values() ->map(function (ReflectionMethod $method) use ($model) { $relation = $method->invoke($model); + if (! $relation instanceof Relation) { + return null; + } + return [ 'name' => $method->getName(), 'type' => Str::afterLast(get_class($relation), '\\'), 'related' => get_class($relation->getRelated()), ]; - }); + }) + ->filter() + ->values(); } /** From b69d284bf865369d516265f222389902b52a002c Mon Sep 17 00:00:00 2001 From: Jess Archer Date: Wed, 20 Jul 2022 11:35:19 +1000 Subject: [PATCH 3/3] Fix model:show when model shares name with a facade --- src/Illuminate/Foundation/Console/ShowModelCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Foundation/Console/ShowModelCommand.php b/src/Illuminate/Foundation/Console/ShowModelCommand.php index 4b386ea16e03..a7671d5321b6 100644 --- a/src/Illuminate/Foundation/Console/ShowModelCommand.php +++ b/src/Illuminate/Foundation/Console/ShowModelCommand.php @@ -437,7 +437,7 @@ protected function columnIsUnique($column, $indexes) */ protected function qualifyModel(string $model) { - if (class_exists($model)) { + if (str_contains($model, '\\') && class_exists($model)) { return $model; }