framework
framework copied to clipboard
[9.x] Add composer autoload and wildcard support to `model:show`
This PR adds composer autoload and wildcard support to model:show as suggested by @driesvints in #44212.
Previous Behaviour
model:show only qualifies model in the App\ (or App\Models\ if exists) directory. It is possible to pass the full model namespace but this quickly becomes inconvenient as the number of sub-namespace levels increase (i.e., App\Foo\Bar\Baz\...\Model).
Current Behaviour
model:show now uses the composer autoload classmap (adapted from Laravel\Tinker\ClassAliasAutoLoader) as well as wildcard matching to qualify model names. In addition, when multiple models are matched the user is presented with the choices and asked to select the desired model.
This allows the user to more quickly select and view the details of a desired model, especially when dealing with models several levels deep.
Examples
// matches model basenames that equal `FooBar`
// - App\Models\FooBar
// - App\Baz\FooBar
model:show FooBar
// matches model basenames that start with `FooBar`
// - App\Models\FooBarFlight
// - App\Baz\FooBarTicket
model:show FooBar*
// matches model basenames that contain `FooBar`
// - App\Models\PlaneFooBar
// - App\Baz\UserFooBarTicket
model:show *FooBar*
// matches models that end in `Bar\FooBar`
// - App\Foo\Bar\FooBar
model:show Bar\\FooBar
// matches model basenames that start with `FooBar` in
// sub-namespaces that contain `Bar`
// - App\Foo\Bar\Baz\FooBarFlight
model:show Bar*\\FooBar*
// matches model basenames === `FooBar` in
// sub-namespaces that contain `Bar\Very`
// - App\Foo\Bar\VeryLongName\FooBar
model:show Bar\\Very*\\FooBar