inspect( $this->argument('model'), $this->option('database') ); } catch (BindingResolutionException $e) { $this->components->error($e->getMessage()); return 1; } $this->display($info); return 0; } /** * Render the model information. * * @return void */ protected function display(ModelInfo $modelData) { $this->option('json') ? $this->displayJson($modelData) : $this->displayCli($modelData); } /** * Render the model information as JSON. * * @return void */ protected function displayJson(ModelInfo $modelData) { $this->output->writeln( (new Collection($modelData))->toJson() ); } /** * Render the model information for the CLI. * * @return void */ protected function displayCli(ModelInfo $modelData) { $this->newLine(); $this->components->twoColumnDetail(''.$modelData->class.''); $this->components->twoColumnDetail('Database', $modelData->database); $this->components->twoColumnDetail('Table', $modelData->table); if ($policy = $modelData->policy ?? false) { $this->components->twoColumnDetail('Policy', $policy); } $this->newLine(); $this->components->twoColumnDetail( 'Attributes', 'type / cast', ); foreach ($modelData->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 ($modelData->relations as $relation) { $this->components->twoColumnDetail( sprintf('%s %s', $relation['name'], $relation['type']), $relation['related'] ); } $this->newLine(); $this->components->twoColumnDetail('Events'); if ($modelData->events->count()) { foreach ($modelData->events as $event) { $this->components->twoColumnDetail( sprintf('%s', $event['event']), sprintf('%s', $event['class']), ); } } $this->newLine(); $this->components->twoColumnDetail('Observers'); if ($modelData->observers->count()) { foreach ($modelData->observers as $observer) { $this->components->twoColumnDetail( sprintf('%s', $observer['event']), implode(', ', $observer['observer']) ); } } $this->newLine(); } /** * Prompt for missing input arguments using the returned questions. * * @return array */ protected function promptForMissingArgumentsUsing(): array { return [ 'model' => fn (): string => suggest('Which model would you like to show?', $this->findAvailableModels()), ]; } }