Guidelines
Authorization
- Use the
Gatefacade to authorize an action in controllers.
Controller
- Use
response()->json()to return a response (when not returning a resource or collection).- Use the
HttpCodeclass to set the status codejson(status: HttpCode::OK).
- Use the
Model
- Always use
Model::shouldBeStrict(). This prevents three things (more details) :- Lazy loading
- Silently discarding attributes
- Silently discarding attributes
Request
- Delete the
authorizemethod if you don’t need it, as the default value is alreadytrue. - Name your request file with the controller name followed by the method name it’s used for.
UserStoreRequestif you need a request in yourUserControllerfor thestoremethod.
- Use array notation
['required', 'string', 'max:20']rather than the string notationrequired|string|max:20as it’s easier to apply custom rules if needed. - All custom validation rules must use snake_case.