class ModelMakeCommand extends GeneratorCommand (View source)

Traits

Properties

protected Factory internal $components

The console components factory.

from  InteractsWithIO
protected InputInterface $input

The input interface implementation.

from  InteractsWithIO
protected OutputStyle $output

The output interface implementation.

from  InteractsWithIO
protected int $verbosity

The default verbosity of output commands.

from  InteractsWithIO
protected array $verbosityMap

The mapping between human readable verbosity levels and Symfony's OutputInterface.

from  InteractsWithIO
protected Signals|null $signals

The signal registrar instance.

from  InteractsWithSignals
static protected array $macros

The registered string macros.

from  Macroable
protected Application $laravel

The Laravel application instance.

from  Command
protected string $signature

The name and signature of the console command.

from  Command
protected string $name

The console command name.

protected string $description

The console command description.

protected string $help

The console command help text.

from  Command
protected bool $hidden

Indicates whether the command should be shown in the Artisan command list.

from  Command
protected bool $isolated

Indicates whether only one instance of the command can run at any given time.

from  Command
protected int $isolatedExitCode

The default exit code for isolated commands.

from  Command
protected array $aliases

The console command name aliases.

from  Command
protected Filesystem $files

The filesystem instance.

from  GeneratorCommand
protected string $type

The type of class being generated.

protected string[] $reservedNames

Reserved names that cannot be used for generation.

from  GeneratorCommand

Methods

Command
resolveCommand(Command|string $command)

Resolve the console command instance for the given command.

int
call(Command|string $command, array $arguments = [])

Call another console command.

int
callSilent(Command|string $command, array $arguments = [])

Call another console command without output.

int
callSilently(Command|string $command, array $arguments = [])

Call another console command without output.

int
runCommand(Command|string $command, array $arguments, OutputInterface $output)

Run the given console command.

ArrayInput
createInputFromArguments(array $arguments)

Create an input instance from the given arguments.

array
context()

Get all of the context passed to the command.

void
configurePrompts(InputInterface $input)

Configure the prompt fallbacks.

mixed
promptUntilValid(Closure $prompt, bool|string $required, Closure|null $validate)

Prompt the user until the given validation callback passes.

?string
validatePrompt(mixed $value, mixed $rules)

Validate the given prompt value using the validator.

getPromptValidatorInstance(mixed $field, mixed $value, mixed $rules, array $messages = [], array $attributes = [])

Get the validator instance that should be used to validate prompts.

array
validationMessages()

Get the validation messages that should be used during prompt validation.

array
validationAttributes()

Get the validation attributes that should be used during prompt validation.

void
restorePrompts()

Restore the prompts output.

void
specifyParameters()

Specify the arguments and options on the command.

array
getArguments()

Get the console command arguments.

array
getOptions()

Get the console command options.

bool
hasArgument(string|int $name)

Determine if the given argument is present.

array|string|bool|null
argument(string|null $key = null)

Get the value of a command argument.

array
arguments()

Get all of the arguments passed to the command.

bool
hasOption(string $name)

Determine if the given option is present.

string|array|bool|null
option(string|null $key = null)

Get the value of a command option.

array
options()

Get all of the options passed to the command.

bool
confirm(string $question, bool $default = false)

Confirm a question with the user.

mixed
ask(string $question, string|null $default = null)

Prompt the user for input.

mixed
anticipate(string $question, array|callable $choices, string|null $default = null)

Prompt the user for input with auto completion.

mixed
askWithCompletion(string $question, array|callable $choices, string|null $default = null)

Prompt the user for input with auto completion.

mixed
secret(string $question, bool $fallback = true)

Prompt the user for input but hide the answer from the console.

string|array
choice(string $question, array $choices, string|int|null $default = null, mixed|null $attempts = null, bool $multiple = false)

Give the user a single choice from an array of answers.

void
table(array $headers, Arrayable|array $rows, TableStyle|string $tableStyle = 'default', array $columnStyles = [])

Format input to textual table.

mixed|void
withProgressBar(iterable|int $totalSteps, Closure $callback)

Execute a given callback while advancing a progress bar.

void
info(string $string, int|string|null $verbosity = null)

Write a string as information output.

void
line(string $string, string|null $style = null, int|string|null $verbosity = null)

Write a string as standard output.

void
comment(string $string, int|string|null $verbosity = null)

Write a string as comment output.

void
question(string $string, int|string|null $verbosity = null)

Write a string as question output.

void
error(string $string, int|string|null $verbosity = null)

Write a string as error output.

void
warn(string $string, int|string|null $verbosity = null)

Write a string as warning output.

void
alert(string $string, int|string|null $verbosity = null)

Write a string in an alert box.

$this
newLine(int $count = 1)

Write a blank line.

void
setInput(InputInterface $input)

Set the input interface implementation.

void
setOutput(OutputStyle $output)

Set the output interface implementation.

void
setVerbosity(string|int $level)

Set the verbosity level.

int
parseVerbosity(string|int|null $level = null)

Get the verbosity level in terms of Symfony's OutputInterface level.

getOutput()

Get the output implementation.

outputComponents()

Get the output component factory implementation.

trap($signals, $callback)

No description

void
untrap()

Untrap signal handlers set within the command's handler.

void
interact(InputInterface $input, OutputInterface $output)

Interact with the user before validating the input.

void
promptForMissingArguments(InputInterface $input, OutputInterface $output)

Prompt the user for any missing arguments.

array
promptForMissingArgumentsUsing()

Prompt for missing input arguments using the returned questions.

void
afterPromptingForMissingArguments(InputInterface $input, OutputInterface $output)

Interact further with the user if they were prompted for missing arguments.

bool
didReceiveOptions(InputInterface $input)

Whether the input contains any options that differ from the default values.

static void
macro(string $name, object|callable $macro)

Register a custom macro.

static void
mixin(object $mixin, bool $replace = true)

Mix another object into the class.

static bool
hasMacro(string $name)

Checks if macro is registered.

static void
flushMacros()

Flush the existing macros.

static mixed
__callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

mixed
__call(string $method, array $parameters)

Dynamically handle calls to the class.

void
__construct(Filesystem $files)

Create a new generator command instance.

void
configureUsingFluentDefinition()

Configure the console command using a fluent definition.

from  Command
void
configureIsolation()

Configure the console command for isolation.

from  Command
int
run(InputInterface $input, OutputInterface $output)

Run the console command.

from  Command
int
execute(InputInterface $input, OutputInterface $output)

Execute the console command.

from  Command
commandIsolationMutex()

Get a command isolation mutex instance for the command.

from  Command
void
fail(Throwable|string|null $exception = null)

Fail the command manually.

from  Command
bool
isHidden()

{@inheritdoc}

from  Command
setHidden(bool $hidden = true)

{@inheritdoc}

from  Command
getLaravel()

Get the Laravel application instance.

from  Command
void
setLaravel(Container $laravel)

Set the Laravel application instance.

from  Command
string
getStub()

Get the stub file for the generator.

bool|null
handle()

Execute the console command.

string
qualifyClass(string $name)

Parse the class name and format according to the root namespace.

string
qualifyModel(string $model)

Qualify the given model class base name.

array<int,string>
possibleModels()

Get a list of possible model names.

array<int,string>
possibleEvents()

Get a list of possible event names.

string
getDefaultNamespace(string $rootNamespace)

Get the default namespace for the class.

bool
alreadyExists(string $rawName)

Determine if the class already exists.

string
getPath(string $name)

Get the destination class path.

string
makeDirectory(string $path)

Build the directory for the class if necessary.

string
buildClass(string $name)

Build the class with the given name.

$this
replaceNamespace(string $stub, string $name)

Replace the namespace for the given stub.

string
getNamespace(string $name)

Get the full namespace for a given class, without the class name.

string
replaceClass(string $stub, string $name)

Replace the class name for the given stub.

string
sortImports(string $stub)

Alphabetically sorts the imports for the given stub.

string
getNameInput()

Get the desired class name from the input.

string
rootNamespace()

Get the root namespace for the class.

string|null
userProviderModel()

Get the model for the default guard's user provider.

bool
isReservedName(string $name)

Checks whether the given name is reserved.

string
viewPath(string $path = '')

Get the first view directory path from the application configuration.

void
addTestOptions()

Add the standard command options for generating matching tests.

bool
handleTestCreation(string $path)

Create the matching test case if requested.

void
createFactory()

Create a model factory for the model.

void
createMigration()

Create a migration file for the model.

void
createSeeder()

Create a seeder file for the model.

void
createController()

Create a controller for the model.

void
createFormRequests()

Create the form requests for the model.

void
createPolicy()

Create a policy file for the model.

string
resolveStubPath(string $stub)

Resolve the fully-qualified path to the stub.

array<string,string>
buildFactoryReplacements()

Build the replacements for a factory.

Details

abstract protected Command resolveCommand(Command|string $command)

Resolve the console command instance for the given command.

Parameters

Command|string $command

Return Value

Command

int call(Command|string $command, array $arguments = [])

Call another console command.

Parameters

Command|string $command
array $arguments

Return Value

int

int callSilent(Command|string $command, array $arguments = [])

Call another console command without output.

Parameters

Command|string $command
array $arguments

Return Value

int

int callSilently(Command|string $command, array $arguments = [])

Call another console command without output.

Parameters

Command|string $command
array $arguments

Return Value

int

protected int runCommand(Command|string $command, array $arguments, OutputInterface $output)

Run the given console command.

Parameters

Command|string $command
array $arguments
OutputInterface $output

Return Value

int

protected ArrayInput createInputFromArguments(array $arguments)

Create an input instance from the given arguments.

Parameters

array $arguments

Return Value

ArrayInput

protected array context()

Get all of the context passed to the command.

Return Value

array

protected void configurePrompts(InputInterface $input)

Configure the prompt fallbacks.

Parameters

InputInterface $input

Return Value

void

protected mixed promptUntilValid(Closure $prompt, bool|string $required, Closure|null $validate)

Prompt the user until the given validation callback passes.

Parameters

Closure $prompt
bool|string $required
Closure|null $validate

Return Value

mixed

protected ?string validatePrompt(mixed $value, mixed $rules)

Validate the given prompt value using the validator.

Parameters

mixed $value
mixed $rules

Return Value

?string

protected Validator getPromptValidatorInstance(mixed $field, mixed $value, mixed $rules, array $messages = [], array $attributes = [])

Get the validator instance that should be used to validate prompts.

Parameters

mixed $field
mixed $value
mixed $rules
array $messages
array $attributes

Return Value

Validator

protected array validationMessages()

Get the validation messages that should be used during prompt validation.

Return Value

array

protected array validationAttributes()

Get the validation attributes that should be used during prompt validation.

Return Value

array

protected void restorePrompts()

Restore the prompts output.

Return Value

void

protected void specifyParameters()

Specify the arguments and options on the command.

Return Value

void

protected array getArguments()

Get the console command arguments.

Return Value

array

protected array getOptions()

Get the console command options.

Return Value

array

bool hasArgument(string|int $name)

Determine if the given argument is present.

Parameters

string|int $name

Return Value

bool

array|string|bool|null argument(string|null $key = null)

Get the value of a command argument.

Parameters

string|null $key

Return Value

array|string|bool|null

array arguments()

Get all of the arguments passed to the command.

Return Value

array

bool hasOption(string $name)

Determine if the given option is present.

Parameters

string $name

Return Value

bool

string|array|bool|null option(string|null $key = null)

Get the value of a command option.

Parameters

string|null $key

Return Value

string|array|bool|null

array options()

Get all of the options passed to the command.

Return Value

array

bool confirm(string $question, bool $default = false)

Confirm a question with the user.

Parameters

string $question
bool $default

Return Value

bool

mixed ask(string $question, string|null $default = null)

Prompt the user for input.

Parameters

string $question
string|null $default

Return Value

mixed

mixed anticipate(string $question, array|callable $choices, string|null $default = null)

Prompt the user for input with auto completion.

Parameters

string $question
array|callable $choices
string|null $default

Return Value

mixed

mixed askWithCompletion(string $question, array|callable $choices, string|null $default = null)

Prompt the user for input with auto completion.

Parameters

string $question
array|callable $choices
string|null $default

Return Value

mixed

mixed secret(string $question, bool $fallback = true)

Prompt the user for input but hide the answer from the console.

Parameters

string $question
bool $fallback

Return Value

mixed

string|array choice(string $question, array $choices, string|int|null $default = null, mixed|null $attempts = null, bool $multiple = false)

Give the user a single choice from an array of answers.

Parameters

string $question
array $choices
string|int|null $default
mixed|null $attempts
bool $multiple

Return Value

string|array

void table(array $headers, Arrayable|array $rows, TableStyle|string $tableStyle = 'default', array $columnStyles = [])

Format input to textual table.

Parameters

array $headers
Arrayable|array $rows
TableStyle|string $tableStyle
array $columnStyles

Return Value

void

mixed|void withProgressBar(iterable|int $totalSteps, Closure $callback)

Execute a given callback while advancing a progress bar.

Parameters

iterable|int $totalSteps
Closure $callback

Return Value

mixed|void

void info(string $string, int|string|null $verbosity = null)

Write a string as information output.

Parameters

string $string
int|string|null $verbosity

Return Value

void

void line(string $string, string|null $style = null, int|string|null $verbosity = null)

Write a string as standard output.

Parameters

string $string
string|null $style
int|string|null $verbosity

Return Value

void

void comment(string $string, int|string|null $verbosity = null)

Write a string as comment output.

Parameters

string $string
int|string|null $verbosity

Return Value

void

void question(string $string, int|string|null $verbosity = null)

Write a string as question output.

Parameters

string $string
int|string|null $verbosity

Return Value

void

void error(string $string, int|string|null $verbosity = null)

Write a string as error output.

Parameters

string $string
int|string|null $verbosity

Return Value

void

void warn(string $string, int|string|null $verbosity = null)

Write a string as warning output.

Parameters

string $string
int|string|null $verbosity

Return Value

void

void alert(string $string, int|string|null $verbosity = null)

Write a string in an alert box.

Parameters

string $string
int|string|null $verbosity

Return Value

void

$this newLine(int $count = 1)

Write a blank line.

Parameters

int $count

Return Value

$this

void setInput(InputInterface $input)

Set the input interface implementation.

Parameters

InputInterface $input

Return Value

void

void setOutput(OutputStyle $output)

Set the output interface implementation.

Parameters

OutputStyle $output

Return Value

void

protected void setVerbosity(string|int $level)

Set the verbosity level.

Parameters

string|int $level

Return Value

void

protected int parseVerbosity(string|int|null $level = null)

Get the verbosity level in terms of Symfony's OutputInterface level.

Parameters

string|int|null $level

Return Value

int

OutputStyle getOutput()

Get the output implementation.

Return Value

OutputStyle

Factory outputComponents()

Get the output component factory implementation.

Return Value

Factory

trap($signals, $callback)

No description

Parameters

$signals
$callback

void untrap()

internal  
 

Untrap signal handlers set within the command's handler.

Return Value

void

protected void interact(InputInterface $input, OutputInterface $output)

Interact with the user before validating the input.

Parameters

InputInterface $input
OutputInterface $output

Return Value

void

protected void promptForMissingArguments(InputInterface $input, OutputInterface $output)

Prompt the user for any missing arguments.

Parameters

InputInterface $input
OutputInterface $output

Return Value

void

protected array promptForMissingArgumentsUsing()

Prompt for missing input arguments using the returned questions.

Return Value

array

protected void afterPromptingForMissingArguments(InputInterface $input, OutputInterface $output)

Interact further with the user if they were prompted for missing arguments.

Parameters

InputInterface $input
OutputInterface $output

Return Value

void

protected bool didReceiveOptions(InputInterface $input)

Whether the input contains any options that differ from the default values.

Parameters

InputInterface $input

Return Value

bool

static void macro(string $name, object|callable $macro)

Register a custom macro.

Parameters

string $name
object|callable $macro

Return Value

void

static void mixin(object $mixin, bool $replace = true)

Mix another object into the class.

Parameters

object $mixin
bool $replace

Return Value

void

Exceptions

ReflectionException

static bool hasMacro(string $name)

Checks if macro is registered.

Parameters

string $name

Return Value

bool

static void flushMacros()

Flush the existing macros.

Return Value

void

static mixed __callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

void __construct(Filesystem $files)

Create a new generator command instance.

Parameters

Filesystem $files

Return Value

void

protected void configureUsingFluentDefinition()

Configure the console command using a fluent definition.

Return Value

void

protected void configureIsolation()

Configure the console command for isolation.

Return Value

void

int run(InputInterface $input, OutputInterface $output)

Run the console command.

Parameters

InputInterface $input
OutputInterface $output

Return Value

int

protected int execute(InputInterface $input, OutputInterface $output)

Execute the console command.

Parameters

InputInterface $input
OutputInterface $output

Return Value

int

protected CommandMutex commandIsolationMutex()

Get a command isolation mutex instance for the command.

Return Value

CommandMutex

void fail(Throwable|string|null $exception = null)

Fail the command manually.

Parameters

Throwable|string|null $exception

Return Value

void

Exceptions

Throwable

bool isHidden()

{@inheritdoc}

Return Value

bool

Command setHidden(bool $hidden = true)

{@inheritdoc}

Parameters

bool $hidden

Return Value

Command

Application getLaravel()

Get the Laravel application instance.

Return Value

Application

void setLaravel(Container $laravel)

Set the Laravel application instance.

Parameters

Container $laravel

Return Value

void

protected string getStub()

Get the stub file for the generator.

Return Value

string

bool|null handle()

Execute the console command.

Return Value

bool|null

protected string qualifyClass(string $name)

Parse the class name and format according to the root namespace.

Parameters

string $name

Return Value

string

protected string qualifyModel(string $model)

Qualify the given model class base name.

Parameters

string $model

Return Value

string

protected array<int,string> possibleModels()

Get a list of possible model names.

Return Value

array<int,string>

protected array<int,string> possibleEvents()

Get a list of possible event names.

Return Value

array<int,string>

protected string getDefaultNamespace(string $rootNamespace)

Get the default namespace for the class.

Parameters

string $rootNamespace

Return Value

string

protected bool alreadyExists(string $rawName)

Determine if the class already exists.

Parameters

string $rawName

Return Value

bool

protected string getPath(string $name)

Get the destination class path.

Parameters

string $name

Return Value

string

protected string makeDirectory(string $path)

Build the directory for the class if necessary.

Parameters

string $path

Return Value

string

protected string buildClass(string $name)

Build the class with the given name.

Parameters

string $name

Return Value

string

Exceptions

FileNotFoundException

protected $this replaceNamespace(string $stub, string $name)

Replace the namespace for the given stub.

Parameters

string $stub
string $name

Return Value

$this

protected string getNamespace(string $name)

Get the full namespace for a given class, without the class name.

Parameters

string $name

Return Value

string

protected string replaceClass(string $stub, string $name)

Replace the class name for the given stub.

Parameters

string $stub
string $name

Return Value

string

protected string sortImports(string $stub)

Alphabetically sorts the imports for the given stub.

Parameters

string $stub

Return Value

string

protected string getNameInput()

Get the desired class name from the input.

Return Value

string

protected string rootNamespace()

Get the root namespace for the class.

Return Value

string

protected string|null userProviderModel()

Get the model for the default guard's user provider.

Return Value

string|null

protected bool isReservedName(string $name)

Checks whether the given name is reserved.

Parameters

string $name

Return Value

bool

protected string viewPath(string $path = '')

Get the first view directory path from the application configuration.

Parameters

string $path

Return Value

string

protected void addTestOptions()

Add the standard command options for generating matching tests.

Return Value

void

protected bool handleTestCreation(string $path)

Create the matching test case if requested.

Parameters

string $path

Return Value

bool

protected void createFactory()

Create a model factory for the model.

Return Value

void

protected void createMigration()

Create a migration file for the model.

Return Value

void

protected void createSeeder()

Create a seeder file for the model.

Return Value

void

protected void createController()

Create a controller for the model.

Return Value

void

protected void createFormRequests()

Create the form requests for the model.

Return Value

void

protected void createPolicy()

Create a policy file for the model.

Return Value

void

protected string resolveStubPath(string $stub)

Resolve the fully-qualified path to the stub.

Parameters

string $stub

Return Value

string

protected array<string,string> buildFactoryReplacements()

Build the replacements for a factory.

Return Value

array<string,string>