Download the PHP package predatorstudio/laravel-attribute-code-generators without Composer

On this page you can find all versions of the php package predatorstudio/laravel-attribute-code-generators. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-attribute-code-generators

Laravel Attribute Code Generators

v1.1

A Laravel package that generates a full CRUD scaffold from PHP 8.1 Attributes placed directly on Eloquent models. One command reads every model in your app, inspects its attributes, and writes controllers, services, repositories, DTOs, resources, migrations, policies, observers, factories, seeders, tests, and routes — only what you asked for, nothing more.

Requirements

Installation

The service provider is auto-discovered via Laravel's package auto-discovery.

Publish the config file to customise paths:

This creates config/crud-generator.php in your application.

Claude Code integration (optional)

Install a /describe-attributes slash command into your project's Claude Code environment:

This copies a prompt file to .claude/commands/describe-attributes.md in your project root. After restarting Claude Code the command is available as a slash command:

Command Description
/describe-attributes Full reference — every attribute, its parameters, generated artifacts, and interaction map
/describe-attributes Seeder Reference for a single attribute (case-insensitive)

Configuration

After publishing the config you can adjust these keys in config/crud-generator.php:

Key Default Description
scan_path app/Models Directory scanned for models (relative to project root). All subdirectories are included recursively.
generate_php_docs false When true, every generated method gets a PHPDoc block with @param and @return annotations.
api_docs_path docs/api Base directory for API documentation files
api_docs_models_path docs/api/models Directory where per-model YAML files are saved
api_docs_main_file docs/api/openapi.yaml Main OpenAPI file regenerated on every crud:sync

Output path overrides

The paths key lets you change the target directory for each generator. All paths are relative to the project root.

Example — if your services live in app/Libs/Services:

The generated UserService will be placed at app/Libs/Services/UserService.php with namespace App\Libs\Services.

Scanning subdirectories & automatic subpath mirroring

Models can be placed in any subdirectory under scan_path. The namespace is inferred from the folder structure, and every generated file mirrors the same subdirectory:

Generated files:

This ensures namespaces stay consistent across the entire generated scaffold without any manual configuration.

Usage

Annotate your model with the attributes that describe what you want generated, then run:

Option Description
--dry-run Preview what would be generated without writing any files
--force Overwrite existing files (asks for confirmation per file)

Available Attributes

#[Crud]

Enables CRUD generation for the model. Optionally restricts which HTTP methods are scaffolded.

#[Route]

Registers the resource route under the given path. Optionally applies middleware.

#[Resource]

Generates an API resource class. Specify which fields to expose, or omit fields to auto-generate from the model's visible fields() columns (respecting hidden: true).

#[Service]

Generates a service class. Pass interface: true to also generate a contract and bind it in the service container.

#[Repository]

Generates a repository class. Pass interface: true to also generate a contract and bind it.

#[DTO]

Generates a Data Transfer Object with readonly properties, a fromArray() factory, and a toArray() method. Fields marked hidden: true in fields() are excluded.

#[Policy]

Generates a policy class for the model.

#[Observer]

Generates an observer class and registers it automatically.

#[Factory]

Generates an Eloquent factory for the model with sensible faker defaults per column type.

#[Seeder]

Generates a database seeder that uses the model's factory to create records. The default count is 10.

#[UseSoftDeletes]

Adds soft-delete support: appends $table->softDeletes() to the generated migration and injects the SoftDeletes trait into the model.

Note: The attribute was renamed from #[SoftDeletes] to #[UseSoftDeletes] in v1.1 to avoid a name collision with the Eloquent SoftDeletes trait.

#[GenerateMigration]

Generates a create_*_table migration based on the model's fields() method. On subsequent runs the package compares saved column names against the current fields() list — if new columns are found it generates an add_columns_to_*_table ALTER migration.

#[ValidateFromMigration]

Generates StoreRequest and UpdateRequest validation rules derived from the migration columns. The UpdateRequest automatically prepends sometimes to every rule, making it suitable for PATCH requests.

Fields marked hidden: true in fields() are excluded from both requests.

#[BackedEnum]

Generates a backed enum for a field. Repeatable — add one per enum field.

Use filename to override the generated class name (useful when the auto-derived name conflicts with something else):

#[Action]

Generates single-purpose action classes (Create, Update, Delete) for the model.

#[GenerateTest]

Generates a feature test for the model's CRUD endpoints.


The fields() method

Define the model's schema by implementing a fields() method. It drives migration generation, validation rules, factories, DTOs, and resource output.

Field keys

Key Type Description
name string Column name
type string Column type (string, text, integer, boolean, foreignId, json, id, timestamps, …)
nullable bool Adds nullable() to the migration column and nullable to validation rules
unique bool Adds unique() to the migration column
default mixed Adds ->default(value) to the migration column
hidden bool Excludes the field from requests, resources, and DTOs

Explicit relation definitions

For foreignId fields you can provide an explicit relation key to control how the BelongsTo relation is generated on the model. Without it the related model is derived automatically from the _id suffix.

When local or foreign differ from defaults the generated belongsTo() call includes the explicit key arguments:


Bindings provider

When interface: true is used on #[Service] or #[Repository], the package writes interface-to-implementation bindings to app/Providers/GeneratedBindingsProvider.php.

The generated block is wrapped in marker comments so that manually added bindings are preserved across runs:


Generated method signatures

All generated methods include explicit return types. Enable PHPDoc blocks via config:

Controller:

Service:


Full example

Running php artisan crud:sync on this model generates:

On the next run, already-generated artifacts are skipped. If new columns are added to fields(), only an ALTER migration is generated for the new columns.

License

MIT


All versions of laravel-attribute-code-generators with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
illuminate/console Version ^10.0|^11.0|^12.0|^13.0
illuminate/filesystem Version ^10.0|^11.0|^12.0|^13.0
illuminate/support Version ^10.0|^11.0|^12.0|^13.0
nikic/php-parser Version ^5.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package predatorstudio/laravel-attribute-code-generators contains the following files

Loading the files please wait ...