Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Php Code Generator Laravel Package

gossi/php-code-generator

A lightweight PHP library for generating PHP code programmatically. Build classes, methods, properties, namespaces, and docblocks through a fluent API, then render valid source files for scaffolding, code generation, and automation workflows.

View on GitHub
Deep Wiki
Context7

Getting Started

This package generates PHP classes (models, controllers, etc.) from configuration, and v0.6-beta.1 adds a profile option and experimental code formatting via gossi/php-code-formatter. Start by publishing the config (php artisan vendor:publish) and reviewing config/code-generator.php for CodeGeneratorConfig options. The first use case is scaffolding a CRUD resource: define your table or schema, run the generator command, and inspect the generated files. Look first at the profile option—it lets you switch between formatting presets—and set enableFormatting to true only if you’re comfortable with experimental output. For existing projects, verify that generated interfaces now carry proper FQCNs (fixed in this release) and that traits are no longer forced into first position.

Implementation Patterns

  • Profile-based generation: Use the new profile option to maintain separate formatting styles per project or per generator run. Combine it with enableFormatting for automatic PSR-12-ish cleanup, but treat it as a post-processing step—review diffs before committing.
  • Workflow integration: Generate into a temporary directory first (--output=tmp/generated), run your test suite or static analysis, then move files into place. This catches the “traits in first position” and FQCN issues early.
  • CRUD scaffolding: Define your model schema (e.g., via migrations or a YAML definition) and generate models, controllers, requests, and routes in one command. Use the profile option to match your team’s code style (e.g., “laravel” vs “psr12”).
  • Incremental regeneration: When adding a column, regenerate only the affected files. Because the package now correctly writes FQCNs for implemented interfaces, you can safely regenerate classes that implement contracts without breaking use statements.
  • Extension points: Hook into the generator’s post-processing events (if exposed) to run your own formatter or linter. The enableFormatting flag is a quick win, but for production pipelines prefer your own pint/php-cs-fixer step to avoid depending on an experimental feature.

Gotchas and Tips

  • PhpFunction is deprecated: If your custom templates or config reference PhpFunction, migrate to the recommended replacement (check issue #35). Deprecation warnings may appear in logs; silence them only after migrating.
  • Experimental formatting: enableFormatting uses gossi/php-code-formatter and is marked “very experimental.” Test on a branch—formatting may alter generated code in unexpected ways (e.g., line breaks in long signatures). Keep a backup or use version control.
  • Profile configuration: The profile option is new; ensure your config file is republished or merged. If you use config caching (php artisan config:cache), clear it after upgrading.
  • Trait ordering fix: The “remove traits in first position” fix (#52) changes generated output. If you have custom templates that assumed traits came first, update them.
  • FQCN parsing fix: Implemented interfaces now get fully qualified names (#51). If you previously worked around this with manual use statements, remove those workarounds to avoid duplicates.
  • Debugging generation: Use --verbose (if available) or inspect the intermediate representation before formatting. The formatter runs after generation, so syntax errors in your definitions will still surface before formatting.
  • Beta stability: v0.6-beta.1 is a beta release. Pin the exact version in composer.json and avoid using it in critical production generators until the formatting feature stabilises.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
pharaonic/laravel-notification-dependencies
beautinow/translug
dev-brainiac/bot-cloaked
octoberrain/html
octoberrain/extension
octoberrain/exception
octoberrain/contracts
frankyso/ipaymu
3mdikram/worldmoneywords
snowsoft/config
itmosoft/laravel-subscriptions
larva/laravel-ai-qwen
adachsoft/api-version-bundle
cgv/localized-resource
noith/settings
kda/laravel-package
kda/filament-dynamic-navigation
bypersoft/signbox
pairus/product-data
fayne/laravel-filament-cms-core