Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 32 additions & 6 deletions src/Illuminate/Foundation/Console/ShowModelCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Illuminate\Contracts\Container\BindingResolutionException;
use Illuminate\Database\Console\DatabaseInspectionCommand;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Str;
use ReflectionClass;
use ReflectionMethod;
Expand Down Expand Up @@ -101,12 +102,27 @@ public function handle()
$class,
$model->getConnection()->getName(),
$model->getConnection()->getTablePrefix().$model->getTable(),
$this->getPolicy($model),
$this->getAttributes($model),
$this->getRelations($model),
$this->getObservers($model),
);
}

/**
* Get the first policy associated with this model.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @return Illuminate\Support\Collection
*/
protected function getPolicy($model)
{
return collect(Gate::policies())
->filter(fn ($policy, $modelClass) => $modelClass === get_class($model))
->values()
->first();
}

/**
* Get the column attributes for the given model.
*
Expand Down Expand Up @@ -264,16 +280,17 @@ protected function getObservers($model)
* @param string $class
* @param string $database
* @param string $table
* @param string $policy
* @param \Illuminate\Support\Collection $attributes
* @param \Illuminate\Support\Collection $relations
* @param \Illuminate\Support\Collection $observers
* @return void
*/
protected function display($class, $database, $table, $attributes, $relations, $observers)
protected function display($class, $database, $table, $policy, $attributes, $relations, $observers)
{
$this->option('json')
? $this->displayJson($class, $database, $table, $attributes, $relations, $observers)
: $this->displayCli($class, $database, $table, $attributes, $relations, $observers);
? $this->displayJson($class, $database, $table, $policy, $attributes, $relations, $observers)
: $this->displayCli($class, $database, $table, $policy, $attributes, $relations, $observers);
}

/**
Expand All @@ -282,18 +299,20 @@ protected function display($class, $database, $table, $attributes, $relations, $
* @param string $class
* @param string $database
* @param string $table
* @param string $policy
* @param \Illuminate\Support\Collection $attributes
* @param \Illuminate\Support\Collection $relations
* @param \Illuminate\Support\Collection $observers
* @return void
*/
protected function displayJson($class, $database, $table, $attributes, $relations, $observers)
protected function displayJson($class, $database, $table, $policy, $attributes, $relations, $observers)
{
$this->output->writeln(
collect([
'class' => $class,
'database' => $database,
'table' => $table,
'policy' => $policy,
'attributes' => $attributes,
'relations' => $relations,
'observers' => $observers,
Expand All @@ -307,19 +326,24 @@ protected function displayJson($class, $database, $table, $attributes, $relation
* @param string $class
* @param string $database
* @param string $table
* @param string $policy
* @param \Illuminate\Support\Collection $attributes
* @param \Illuminate\Support\Collection $relations
* @param \Illuminate\Support\Collection $observers
* @return void
*/
protected function displayCli($class, $database, $table, $attributes, $relations, $observers)
protected function displayCli($class, $database, $table, $policy, $attributes, $relations, $observers)
{
$this->newLine();

$this->components->twoColumnDetail('<fg=green;options=bold>'.$class.'</>');
$this->components->twoColumnDetail('Database', $database);
$this->components->twoColumnDetail('Table', $table);

if ($policy) {
$this->components->twoColumnDetail('Policy', $policy);
}

$this->newLine();

$this->components->twoColumnDetail(
Expand Down Expand Up @@ -370,7 +394,9 @@ protected function displayCli($class, $database, $table, $attributes, $relations
if ($observers->count()) {
foreach ($observers as $observer) {
$this->components->twoColumnDetail(
sprintf('%s', $observer['event']), implode(', ', $observer['observer']));
sprintf('%s', $observer['event']),
implode(', ', $observer['observer'])
);
}
}

Expand Down