timwassenburg/laravel-improved-resource-controllers

Generate complete resource controllers

Downloads

27

Stars

4

Version

v1.0.4
Logo

Latest Version on Packagist Total Downloads License


Table of Contents

  1. Features
  2. Getting started
  3. Usage
  4. Variables
  5. More generator packages
  6. Contributing
  7. License

Features

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.

Getting started

Installation

Require the package with composer.

composer require timwassenburg/laravel-improved-resource-controllers --dev

Publish config (optional)

php artisan vendor:publish --provider="TimWassenburg\ImprovedResourceControllers\ImprovedResourceControllersServiceProvider" --tag="config"

Publish stubs (optional)

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"

Usage

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.

Default resource controller

php artisan make:controller CustomerController --resource

Example output

Default API resource controller

php artisan make:controller CustomerController --resource --api

Example output

Model resource controller

php artisan make:controller CustomerController --resource --model=Customer

Example output

Model API resource controller

php artisan make:controller CustomerController --resource --model=Customer --api

Example output

Nested resource controller

php artisan make:controller CityController --resource --parent=Country --model=City

Example output

Nested API resource controller

php artisan make:controller CityController --resource --parent=Country --model=City --api

Example output

Variables

In the stubs you can use the following variables.

General

Variable Output
{{ namespace }} App\Http\Controllers
{{ namespacedModel }} App\Models\Order
{{ class }} OrderController
{{ model }} Order
{{ modelVariable }} order
{{ modelVariablePlural }} orders

With parent (--parent=Customer)

Variable Output
{{ namespacedParentModel }} App\Models\Customer
{{ parentModelVariable }} customer
{{ parentModelVariablePlural }} customers

More generator packages

Looking for more ways to speed up your workflow? Make sure to check out these packages.

Contributing

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!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

The MIT License (MIT). Please see License File for more information.

timwassenburg

Author

timwassenburg