Strategy
Defaults
First and foremost, Laravel provides the most value when you write things the way Laravel intended you to write. It means better and more extensive use of native laravel features or Laravel “products” like Nova. Whenever you do something differently, make sure you have a justification for why you didn’t follow the defaults.
It frames your work with a set of guidelines that you can follow to ensure every member of your team is on the same page. It provides many complex, tedious, and battle-tested features for free, so you can focus on coding what is specific to your project. There are edge cases to not stick to the defaults.
Secondary, Laravel often provides few ways/APIs to achieve your goals, in this document we try to list all our conventions to keep our code more consistent and use only one way.
Structure
Stick to the default folder structure, that is one of the reasons why we are using a framework.
Benefits with sticking to the default structure as much as possible:
- Convenience. Laravel’s default way of doing things is documented. When you come back on a project, weeks or months later, you will thank your past self for this.
- Working with teammates is considerably easier. They know Laravel, just like you. Use this common knowledge to help the project move forward instead of reinventing the wheel every time.
Single Responsibility
Keeping a single responsibility pattern (Referencing back to the S in Single Responsibility) in your code is very good for splitting functionality into its own container, making your code more readable and maintainable. Taylor, the creator of Laravel also recommends the single responsibility pattern.
He said: A controller should handle only the relevant CRUD operations and its related functions, for instance if you have a PostController, it should only have index,create,store,show,edit,update,destroy the default ResourceController and then related methods like PublisPost. It is all relevant to a Post. This way of thinking across all functionalities in the system will result in a better product to maintain.
