Downloads
Stars
Version
This simple package extends the php artisan make:controller
command and generates
resource controllers with working resource functions out of the box to prevent you from writing
the same basic controller functions over and over again.
Keep in mind the improved resource controllers are only meant as a starting point.
You still have to add your own routes, validation, migrations, etc.
Require the package with composer.
composer require timwassenburg/laravel-improved-resource-controllers --dev
php artisan vendor:publish --provider="TimWassenburg\ImprovedResourceControllers\ImprovedResourceControllersServiceProvider" --tag="config"
To change the generated resource controllers you can override the stubs and adjust it to your liking. The stubs will be stored in /resources/stubs.
php artisan vendor:publish --provider="TimWassenburg\ImprovedResourceControllers\ImprovedResourceControllersServiceProvider" --tag="stubs"
The idea behind this package is that you can keep using the make:controller commands you are already used to. So no need to change your muscle memory. Checkout the example output to see the result for each command.
php artisan make:controller CustomerController --resource
php artisan make:controller CustomerController --resource --api
php artisan make:controller CustomerController --resource --model=Customer
php artisan make:controller CustomerController --resource --model=Customer --api
php artisan make:controller CityController --resource --parent=Country --model=City
php artisan make:controller CityController --resource --parent=Country --model=City --api
In the stubs you can use the following variables.
Variable | Output |
---|---|
{{ namespace }} | App\Http\Controllers |
{{ namespacedModel }} | App\Models\Order |
{{ class }} | OrderController |
{{ model }} | Order |
{{ modelVariable }} | order |
{{ modelVariablePlural }} | orders |
Variable | Output |
---|---|
{{ namespacedParentModel }} | App\Models\Customer |
{{ parentModelVariable }} | customer |
{{ parentModelVariablePlural }} | customers |
Looking for more ways to speed up your workflow? Make sure to check out these packages.
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
git checkout -b feature/AmazingFeature
)git commit -m 'Add some AmazingFeature'
)git push origin feature/AmazingFeature
)The MIT License (MIT). Please see License File for more information.