inspect( $this->argument('model'), $this->option('database') ); } catch (BindingResolutionException $e) { $this->components->error($e->getMessage()); return 1; } $this->display( $info['class'], $info['database'], $info['table'], $info['policy'], $info['attributes'], $info['relations'], $info['events'], $info['observers'] ); return 0; } /** * Render the model information. * * @param class-string<\Illuminate\Database\Eloquent\Model> $class * @param string $database * @param string $table * @param class-string|null $policy * @param \Illuminate\Support\Collection $attributes * @param \Illuminate\Support\Collection $relations * @param \Illuminate\Support\Collection $events * @param \Illuminate\Support\Collection $observers * @return void */ protected function display($class, $database, $table, $policy, $attributes, $relations, $events, $observers) { $this->option('json') ? $this->displayJson($class, $database, $table, $policy, $attributes, $relations, $events, $observers) : $this->displayCli($class, $database, $table, $policy, $attributes, $relations, $events, $observers); } /** * Render the model information as JSON. * * @param class-string<\Illuminate\Database\Eloquent\Model> $class * @param string $database * @param string $table * @param class-string|null $policy * @param \Illuminate\Support\Collection $attributes * @param \Illuminate\Support\Collection $relations * @param \Illuminate\Support\Collection $events * @param \Illuminate\Support\Collection $observers * @return void */ protected function displayJson($class, $database, $table, $policy, $attributes, $relations, $events, $observers) { $this->output->writeln( (new Collection([ 'class' => $class, 'database' => $database, 'table' => $table, 'policy' => $policy, 'attributes' => $attributes, 'relations' => $relations, 'events' => $events, 'observers' => $observers, ]))->toJson() ); } /** * Render the model information for the CLI. * * @param class-string<\Illuminate\Database\Eloquent\Model> $class * @param string $database * @param string $table * @param class-string|null $policy * @param \Illuminate\Support\Collection $attributes * @param \Illuminate\Support\Collection $relations * @param \Illuminate\Support\Collection $events * @param \Illuminate\Support\Collection $observers * @return void */ protected function displayCli($class, $database, $table, $policy, $attributes, $relations, $events, $observers) { $this->newLine(); $this->components->twoColumnDetail(''.$class.''); $this->components->twoColumnDetail('Database', $database); $this->components->twoColumnDetail('Table', $table); if ($policy) { $this->components->twoColumnDetail('Policy', $policy); } $this->newLine(); $this->components->twoColumnDetail( 'Attributes', 'type / cast', ); foreach ($attributes as $attribute) { $first = trim(sprintf( '%s %s', $attribute['name'], (new Collection(['increments', 'unique', 'nullable', 'fillable', 'hidden', 'appended'])) ->filter(fn ($property) => $attribute[$property]) ->map(fn ($property) => sprintf('%s', $property)) ->implode(', ') )); $second = (new Collection([ $attribute['type'], $attribute['cast'] ? ''.$attribute['cast'].'' : null, ]))->filter()->implode(' / '); $this->components->twoColumnDetail($first, $second); if ($attribute['default'] !== null) { $this->components->bulletList( [sprintf('default: %s', $attribute['default'])], OutputInterface::VERBOSITY_VERBOSE ); } } $this->newLine(); $this->components->twoColumnDetail('Relations'); foreach ($relations as $relation) { $this->components->twoColumnDetail( sprintf('%s %s', $relation['name'], $relation['type']), $relation['related'] ); } $this->newLine(); $this->components->twoColumnDetail('Events'); if ($events->count()) { foreach ($events as $event) { $this->components->twoColumnDetail( sprintf('%s', $event['event']), sprintf('%s', $event['class']), ); } } $this->newLine(); $this->components->twoColumnDetail('Observers'); if ($observers->count()) { foreach ($observers as $observer) { $this->components->twoColumnDetail( sprintf('%s', $observer['event']), implode(', ', $observer['observer']) ); } } $this->newLine(); } }