| Install | |
|---|---|
composer require rahasistiyak/laravel-super-artisan |
|
| Latest Version: | 1.0.0 |
| PHP: | >=8.0 |
Super Artisan is a powerful Laravel package that enhances the Artisan console to streamline repetitive development tasks. The make:super command generates multiple files (e.g., models, controllers, migrations, views, or front-end components) in a single command, with support for custom paths and design patterns like MVC, repository, or service. The run:workflow command executes predefined sequences of Artisan commands for tasks like deployment.
Install the package via Composer:
composer require rahasistiyak/laravel-super-artisan
Publish the configuration and stub files:
php artisan vendor:publish --tag=super-artisan-config
php artisan vendor:publish --tag=super-artisan-stubs
This creates:
config/super-artisan.php: Configuration for blueprints and workflows.stubs/vendor/super-artisan/: Customizable stub files.make:super CommandThe make:super command generates files for a resource (e.g., Post) with customizable paths and patterns. By default, it uses standard Laravel directories, but you can optionally specify custom paths.
Syntax:
php artisan make:super {name} [--livewire|--vue|--react] [--path={path}] [--controller_path={path}] [--model_path={path}] [--view_path={path}] [--migration_path={path}] [--pattern=repository|service]
Options:
--livewire: Generate a Livewire component (in app/Livewire and resources/views/livewire).--vue: Generate a Vue component (in resources/js).--react: Generate a React component (in resources/js).--path={path}: (Optional) Base path for controllers and views/components (e.g., Admin places controllers in app/Http/Controllers/Admin and views in resources/views/Admin or resources/js/Admin).--controller_path={path}: (Optional) Subfolder within app/Http/Controllers (e.g., Admin places controllers in app/Http/Controllers/Admin).--model_path={path}: (Optional) Subfolder within app/Models (e.g., Custom creates app/Models/Custom/{name}.php).--view_path={path}: (Optional) Subfolder within resources/views (for Blade/Livewire) or resources/js (for Vue/React).--migration_path={path}: (Optional) Subfolder within database/migrations.--pattern=repository|service: (Optional) Generate files for repository (with interface and controller injection) or service pattern.Note: Only one of --livewire, --vue, or --react can be used. Specifying multiple will result in an error.
Examples:
Default MVC with Blade Views:
php artisan make:super Post
Generates:
app/Models/Post.phpdatabase/migrations/*_create_posts_table.phpapp/Http/Controllers/PostController.phpresources/views/post/index.blade.php, create.blade.php, edit.blade.php, show.blade.phpLivewire with Default Paths:
php artisan make:super Post --livewire
Generates:
app/Models/Post.phpdatabase/migrations/*_create_posts_table.phpapp/Http/Controllers/PostController.phpapp/Livewire/Post.phpresources/views/livewire/post.blade.phpLivewire with Custom View Path:
php artisan make:super Post --livewire --view_path=admin/posts
Generates:
app/Models/Post.phpdatabase/migrations/*_create_posts_table.phpapp/Http/Controllers/PostController.phpapp/Livewire/admin/posts/Post.phpresources/views/livewire/admin/posts/post.blade.phpVue with Default Path:
php artisan make:super Post --vue
Generates:
app/Models/Post.phpdatabase/migrations/*_create_posts_table.phpapp/Http/Controllers/PostController.phpresources/js/components/Post.vueVue with Custom Path:
php artisan make:super Post --vue --path=Admin
Generates:
app/Models/Post.phpdatabase/migrations/*_create_posts_table.phpapp/Http/Controllers/Admin/PostController.phpresources/js/Admin/Post.vueRepository Pattern with Custom Controller Path:
php artisan make:super Post --pattern=repository --controller_path=Admin
Generates:
app/Models/Post.phpdatabase/migrations/*_create_posts_table.phpapp/Http/Controllers/Admin/PostController.php (with repository injection)app/Repositories/PostRepository.phpapp/Repositories/PostRepositoryInterface.phpapp/Providers/RepositoryServiceProvider.phpresources/views/post/index.blade.php, etc.Custom Model Path:
php artisan make:super Post --model_path=Custom
Generates:
app/Models/Custom/Post.phpdatabase/migrations/*_create_posts_table.phpapp/Http/Controllers/PostController.phpresources/views/post/*.blade.phpError on Multiple Front-end Options:
php artisan make:super Post --livewire --vue
Output: Only one of --livewire, --vue, or --react can be used.
run:workflow CommandExecute a sequence of Artisan commands defined in config/super-artisan.php.
Syntax:
php artisan run:workflow {workflow}
Example:
php artisan run:workflow deploy
Executes commands like optimize:clear, migrate --force, etc., as defined in the deploy workflow.
The config/super-artisan.php file allows you to define custom blueprints (file generation templates) and workflows (command sequences).
Define sets of files to generate. Example:
'blueprints' => [
'crud' => [
'description' => 'Generates a full CRUD stack.',
'commands' => [
'make:model {name} -m -f',
'make:controller {name}Controller --resource --model={name}',
],
],
],
Define sequences of Artisan commands. Example:
'workflows' => [
'deploy' => [
'description' => 'Clears caches and runs migrations.',
'commands' => [
'optimize:clear',
'migrate --force',
'route:cache',
'view:cache',
],
],
],
Published stubs are located in stubs/vendor/super-artisan/. Modify these to customize generated files:
view_*.stub: Blade view templates.vue_component.stub: Vue component template.react_component.stub: React component template.repository.stub: Repository class template.repository_interface.stub: Repository interface template.repository_controller.stub: Controller with repository injection.service.stub: Service class template.When using --pattern=repository, the package generates:
app/Repositories/{name}Repository.php).app/Repositories/{name}RepositoryInterface.php).app/Http/Controllers/*/{name}Controller.php).app/Providers/RepositoryServiceProvider.php to connect the interface to the repository.This promotes loose coupling and maintainable code.
Run tests to ensure the package works as expected:
vendor/bin/phpunit
Tests verify file generation, path handling, repository bindings, and error cases (e.g., multiple front-end options).
Contributions are welcome! Please submit pull requests or issues to the GitHub repository.
This package is licensed under the MIT License.
For any questions or support, you can reach us at: Email: rahasistiyak.official@gmail.com