- Гайд основан на https://spatie.be/guidelines/laravel-php
- Соглашения принятые в уже устоявшейся кодовой базе имеют приоритет над данным гайдом
Configuration files must use kebab-case.
Configuration keys must use snake_case.
Do not use the env helper outside of configuration files. Create a configuration value from the env variable like above.
The names given to artisan commands should all be kebab-cased.
A command should always give some feedback on what the result is. Minimally you should let the handle method spit out a comment at the end indicating that all went well.
When the main function of a result is processing items, consider adding output inside of the loop, so progress can be tracked. Put the output before the actual process. If something goes wrong, this makes it easy to know which item caused the error.
At the end of the command, provide a summary on how much processing was done.
Public-facing urls must use kebab-case.
Prefer to use the route tuple notation when possible.
Route names must use camelCase.
All routes have an http verb, that's why we like to put the verb first when defining a route. It makes a group of routes very readable. Any other route options should come after it.
# Good: all http verbs come first
# Bad: http verbs not easily scannable
Route parameters should use camelCase.
A route url should not start with / unless the url would be an empty string.
Controllers that control a resource must use the plural resource name.
Try to keep controllers simple andTry to keep controllers simple and stick to Api Design Guide keywords (g
et, replace, patch, delete, search).
This is a loose guideline that doesn't need to be enforced.
View files must use camelCase.
When using multiple rules for one field in a form request, avoid using |, always use array notation. Using an array notation will make it easier to apply custom rule classes to a field.
All custom validation rules must use snake_case:
Indent using four spaces.
Don't add spaces after control structures.
Policies must use camelCase.
Try to name abilities using default CRUD words. One exception: replace show with view. A server shows a resource, a user views it.
Translations must be rendered with the
__ function. We prefer using this over
@lang in Blade views because
__ can be used in both Blade views and regular PHP code. Here's an example:
Generally controllers are named by the plural form of their corresponding resource and a
Controller suffix. This is to avoid naming collisions with models that are often equally named.
When writing non-resourceful controllers you might come across invokable controllers that perform a single action. These can be named by the action they perform again suffixed by Controller.
RESOURCES (AND TRANSFORMERS)
Both Eloquent resources and Fractal transformers are plural resources suffixed with
Transformeraccordingly. This is to avoid naming collisions with models.
Events will often be fired before or after the actual event. This should be very clear by the tense used in their name.
ApprovingLoan before the action is completed and
LoanApproved after the action is completed.
Listeners will perform an action based on an incoming event. Their name should reflect that action with a
Listener suffix. This might seem strange at first but will avoid naming collisions with jobs.
To avoid naming collisions we'll suffix commands with
Command, so they are easily distinguishable from jobs.
Again to avoid naming collisions we'll suffix mailables with
Generally domains (domain directories) should be named by the plural form without
Models should be named by the singular form without
QUERIES from spatie/laravel-query-builder
Queries are named by the plural form of their corresponding resource and a
An action name should describe what it does and have