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:ControllerNameCreate a model:
bash
php snappy generate model:ModelNameCreate a middleware:
bash
php snappy generate middleware:MiddlewareName2. 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-model3. 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:OtherModelName4. Create controller with method(s)
Create controller with all methods (get,post,put,patch,delete):
bash
php snappy generate controller:ControllerName --with-methodsCreate controller with one or more methods separated by commas
bash
php snappy generate controller:ControllerName --with-methods:get,post,put,patch,delete5. Create controller with model and middleware (same name)
This creates:
- Controller:
ControllerName - Model:
ControllerName - Middleware:
ControllerNamewithout/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