Skip to content

CLI

Snappy has CLI feature to create cotroller, model or middlerware automatically to ease and standarized all the files

Generate Controller, Model, and Middleware

Use the generate command to programmatically scaffold framework components with consistent structure.

1. Basic commands

Create a controller:

bash
php snappy generate controller:ControllerName

Create a model:

bash
php snappy generate model:ModelName

Create a middleware:

bash
php snappy generate middleware:MiddlewareName

2. Create controller with model (same name)

This creates a controller and a model with the same base name as ControllerName.

bash
php snappy generate controller:ControllerName --with-model

3. Create controller with model (different name)

This creates a controller named ControllerName and a model named OtherModelName.

bash
php snappy generate controller:ControllerName --with-model:OtherModelName

4. Create controller with method(s)

Create controller with all methods (get,post,put,patch,delete):

bash
php snappy generate controller:ControllerName --with-methods

Create controller with one or more methods separated by commas

bash
php snappy generate controller:ControllerName --with-methods:get,post,put,patch,delete

5. Create controller with model and middleware (same name)

This creates:

  • Controller: ControllerName
  • Model: ControllerName
  • Middleware: ControllerName without/with same method(s) as in making the controller
bash
php snappy generate controller:ControllerName --with-model --with-middleware

ℹ️ NOTE

--with-middleware always generates middleware using the same name as ControllerName.

If you need a different middleware name, create it separately using:

bash
php snappy generate middleware:MiddlewareName