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

Archetype Laravel Package

ajthinking/archetype

Archetype is a Laravel code generation package that lets you define models, migrations, controllers and more through a fluent PHP API, then scaffolds the files instantly—speeding up new features and project setup.

View on GitHub
Deep Wiki
Context7
v2.0.1

Maintenance only. No API changes — nothing here can break existing usage.

v2.0.0 shipped the php-parser 5 port in May 2024 having never been tested against any PHP or Laravel version currently in use: the CI matrix still targeted PHP 7.4/8.0 with Laravel 6/7/8, and hadn't run since. The package worked; there was just no evidence of it. This release supplies the evidence and fixes what turned up along the way.

Supported versions

Archetype PHP Laravel php-parser
2.x 8.1–8.4 10, 11, 12, 13 ^5.0
1.x 7.4–8.1 6–9 ^4.11

Verified across twelve PHP × Laravel combinations in CI, plus macOS and PHPStan. Laravel 13 is included because statamic/cms 6 already allows it, so people were running Archetype there untested.

Fixed

  • ->throw() had matched nothing since 2.0.0. php-parser 5 removed Stmt\Throw_ and the class map still pointed at it. Now maps to Expr\Throw_, with a regression test.
  • getReflection() caught Exception instead of Throwable. A file whose parent class or trait can't be autoloaded raises an Error, which escaped and killed the whole query rather than skipping that one file. Affects LaravelFile::models(), controllers() and serviceProviders().
  • Seven implicit-nullable parameters that raised deprecation notices on PHP 8.4.
  • commands_root and controllers_root in the shipped config both pointed at app/HTTP/Controllers.

Packaging

Declares a php requirement for the first time (^8.1). The upper bound is deliberate: PHP 9 removes dynamic properties, which the AST node-identity mechanism still relies on, so Composer declining the install beats handing you a package that fatals.

Also adds the missing LICENSE.md, a changelog, and a Dependabot config.

Upgrading

From 2.0.0 — drop-in, provided you're on PHP 8.1+.

From 1.x — worth doing. 1.x pins nikic/php-parser to ^4.11, which can't coexist with anything needing php-parser 5, Pest 3 and newer included. If Composer refuses to resolve ajthinking/archetype, that's why. No changes to your own code are required.

Compatibility

statamic/cms is the largest consumer, and this release was checked against it specifically. Real installs of Statamic 5 (Laravel 12) and Statamic 6 (Laravel 13) both resolve 2.0.1 and produce byte-identical output to 2.0.0 across every code path Statamic exercises. Statamic 4 and 3.4 pin ^1.0.3 and are unaffected.

Full details in CHANGELOG.md and #87.

v2.0.0
  • Add support for php-parser 5, Drops support for php parser 4.

Thanks to @jasonvarga ✨

v1.1.5

Please see #77 for details.

v1.1.4

This feature provides a BuilderFactory instance when passing a closure to insertStmt.

PHPFile::make()->class(\App\Dummy::class)
  ->astQuery()
  ->class()
  ->insertStmt(function(BuilderFactory $builder) {
	  return $builder->property('someProperty')->getNode();
  })
  ->commit()
  ->end()
  ->preview();
v1.1.3

When astQuery()->insertStmt(.....) had no matches to operate on, it added the node to the end of the file. This was fixed by adding a guard clause.

v1.1.2
  • Improve pretty printing when creating new classes
  • Adds missing types
  • Remove unused dev dependency
  • new ASTQueryBuilder withEach method
  • No more magic for phpparser classmap, use explicit methods instead
  • Fix an issue where weak comparison caused flakiness
v1.1.1
  • Use dependency injection for maker
  • Fix most phpstan level 0 errors
v1.1.0

Makers

PHPFile::make() now return a Maker instance. Makers allows creating files from a template, for instance:

PHPFile::make()->file('scripts.php')
PHPFile::make()->class(\App\Car::class)

We can implement a custom maker and attaching it to the property "maker" on the File instance.

Internal changes

File methods no longer rely on obscure __call magic, instead minimal stubs are implemented to explicitly forward calls to the corresponding endpoint class.

v1.0.3

Avoid Str macros which may cause segmentation fault in statamic/cms

v1.0.2
v1.0.1

Fixes bug when creating classes.

Now we can create classes like so:

namespace App;

PHPFile::make()->class(Models\Car::class);
PHPFile::make()->class(\App\Models\Car::class);
PHPFile::make()->class('App\Models\Car');
PHPFile::make()->class('\App\Models\Car');
PHPFile::make()->class('app/Models/Car.php');

all of these will write two app/Models/Car.php.

v1.0.0

Welcome to v1.0.0 :green_heart:

AstQueryBuilder

  • Adds ability to enter Node class and properties in one go:
$astQuery->classMethod('name->name')
  • Adds HigherOrderWhere which is a short syntax for where callbacks:
$this->file->astQuery()
    ->class()
    ->property()
    ->where->propertyProperty('name->name')->is($key)->get()
    ->replace(function() {
        ...
    };
  • Auto resolving where clauses allows for leaving a where clause without get(). Results are evaluated to see if they have results (considered thruty) or empty (falsy).
  • Adds Dumpable proxies on astQueryBuilder for ->dd->something() and ->dump->another
  • Adds missing PhpParser types in class map
  • Remove option to use _-postfixed node types in class map
  • Adds an opt-in visualizer/debug tool, see: https://github.com/ajthinking/archetype/pull/45
  • Numerous bugfixes

Endpoints

  • Improved ClassConst

Misc

  • fromString can allow pseudo php
PHPFile::addMissingTags()->fromString('$hey = 1337')
  • Allow reading files outside of the input root using an absolute path
  • Add Tappable and Dumpable traits

Discontinued features :warning: :skull:

In order to tighten this package up and consolidate around primary features, we will drop the following incomplete/broken functionality:

  • Schema
  • Project
  • Generators
  • Trait endpoint (planned to be revived in a better form)

Furthermore,

  • Remove aliases for PHPFile and LaravelFile to enforce explicit facade usage
  • Remove doctrine/dbal dependency

Internal changes

  • All tests are moved to pest :rocket:
  • Introduce TestablePHPFile facade.
  • Introduce TestableAstQueryBuilder facade.

Missing and broken

  • The docs are still not near as good as they should be.
  • Some formatting bugs persist. It is most likely related to format preserving pretty printing. See incomplete test
v1.0.0-candidate

Whats new?

  • Adds remove() ability for class constants.

Discontinued features

In order to tighten this package up and consolidate around primary features, we will drop the following:

  • Schema
  • Project
  • Generators

Most of these feature were incomplete or otherwise broken. A side effect of this is we will no longer be depending on doctrine/dbal.

Tests

All tests are moved to pest and many uses an internal TestablePHPFile facade.

v0.2.8

Better array formatting 🎉 🎉 🎉 Works for newly created, loaded or modified code.

class Finally
{
    protected $empty = [];
    
    protected $one = [
        'one',
    ];
    
    protected $moreThanOne = [
        'one',
        'two',
    ];
}

Thanks for spotting this @jackmcdade

v0.2.7

Fixes an issue with doctrine/dbal

v0.2.6

:bug: Fix bug in notInOperator by @ordago 🔒 Allow doctrine/dbal ^2.10 by @WorldSeso7 :white_check_mark: Bump dependecies, typos and test updates

v0.2.5

Include nikic/php-parser as a dependency, don't assume it is included elsewhere.

v0.2.4
v0.2.3

Rename mismatching class name/file name. Fixes #15

v0.2.2

Support for class constant

$file->classConstant('HOME')

Thanks to @seryak

v0.2.1

v0.2.1 :rocket:

  • Tests on Laravel 8
  • Format preserving code manipulation
  • Ignores abstract models
v0.1.3

Don't use facade aliases which might be unavailable.

v0.1.2
v0.1.1

Fix class resolving when using archetype schema in remote context

v0.1.0

Archetype v0.1.0 :rocket:

  • Happy to announce a core set of features including some experiments 🔥
  • This package does not yet strictly follow semver 😬
  • Need feedback 🙏

v0.0.18
v0.0.17
v0.0.16
v0.0.15
v0.0.14
v0.0.13

In the astQuery(), you can now access general classes/objects/structures with ->methodCall() or similar. To enter a property, simply use ->stmts without ()

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.
socialdept/atp-orm
cboxdk/laravel-assistant-client
socialdept/atp-resolver
socialdept/tenant-domains
tautvydasr/blade-class-names
socialdept/color-scales
maherelgamil/controller
coleus/widgets
coleus/table
coleus/users
coleus/music
coleus/health
coleus/calendar
coleus/notes
coleus/support
coleus/settings
coleus/apps
seampact/laravel
emmyconceptng/laravel-ng-postcode
jjsquady/round-robin