ronasit / larabuilder
A great tool for creating and modifying PHP classes in Laravel, providing utilities to generate boilerplate code, add methods, properties, and annotations with ease.
Installs: 119
Dependents: 1
Suggesters: 0
Security: 0
Stars: 2
Watchers: 0
Forks: 0
Open Issues: 3
pkg:composer/ronasit/larabuilder
Requires
- php: ^8.4
- laravel/framework: ^12.28
- nikic/php-parser: ^5.6
Requires (Dev)
- laravel/pint: ^1.25
- orchestra/testbench: ^10.6
- php-coveralls/php-coveralls: ^2.8
- phpunit/phpunit: ^12.3
- ronasit/laravel-helpers: >=3.5.8
This package is auto-updated.
Last update: 2026-01-16 07:38:57 UTC
README
Laravel Builder
Installation
composer require ronasit/larabuilder --dev
Usage
The logic of the package usage consists of the three stages:
- Open a
phpfile - Call required class modifications methods
- Render modified class structure and overwrite existing file
new PHPFileBuilder(app_path('Models/User.php')) ->addArrayPropertyItem('fillable', 'is_active') ->setProperty('casts', [ 'is_active' => 'boolean', ], AccessModifierEnum::Protected) ->save();
Features
setProperty
Add new class property with the passed value and passed access level in case property does not exist in the class. Otherwise will change already existing class property's value AND access level
addArrayPropertyItem
Add new item to the array class property. Will add new property in case it does not exist yet.
removeArrayPropertyItem
Remove items from the array class property. If the property or item does not exist no action is taken.
addImports
Add new imports to the file. This method will add a new import only in case it does not exist yet, preventing duplicate use statements.
Special Laravel structure builders
Bootstrap app
To modify the Laravel bootstrap app file, use special AppBootstrapBuilder:
new AppBootstrapBuilder()->addExceptionsRender(ExpectationFailedException::class, ' throw $exception; ')->save();
This builder has all the features described above and the special methods:
addExceptionsRender
Adds a new exception render to the withExceptions called method in case it does not exist yet. Does not modify already added
render for the passed exception class.
Note Need to provide the full exception class name (FQCN) to the method, it automatically imports it.