composer require ronasit/larabuilder --devThe 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();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
Add new item to the array class property. Will add new property in case it does not exist yet.
Remove items from the array class property. If the property or item does not exist no action is taken.
Insert the provided code into the specified method body at the desired position - by default, to the end of the method.
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.
Add new use TraitName; statements to a class, trait, or enum. This method automatically adds the corresponding use imports at the top of the file and prevents duplicate trait usages.
Note: Need to provide the full trait class name (FQCN); the method will import it automatically.
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:
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.