Repository navigation
Programming Rules & Standard
Esteban Alvarez Zuluaga edited this page Sep 23, 2025
·
22 revisions
PHP code must adhere when possible to standard PSR-12.
- There should be type annotations where possible, for parameters and return values in functions, classes and methods
- Utilize dependency inversion where possible
- There should be only one class per file, and where possible have the file name match the class name
- Do not carry out "echo" operations inside controllers
- Functionality other than transfering information to render the view, such as validation, or reusable logic should be done in external utils
- Do not import controllers in other controllers
- Send information to the front end in a single associative array
bash $viewDataeg. view(example.index)->with('viewData',$viewData) - Do not send visual layer information through a controller, eg. "title", "subtitle" CHECK
- Only store primitive types in session, never objects
- Always use getters & setters when using objects
- Always do eager loading when possible to minimize database querying
- Try to minimize the amount of results from a db query, that is, if only products with id=3 are needed, dont load all products
- Only one table is to be created per migration file
- There should be a comment in each Model file with information pertaining to the attributes as follows:
/**
* PRODUCT ATTRIBUTES
* $this->attributes['id'] - int - contains the product primary key (id)
* $this->attributes['name'] - string - contains the product name
- Fillable attributes must be specified after the comment in a single line
- Validations for creating the class are to be done in a static function inside the model file for the class
- Getters and setters must be included for all attributes, except setters for id and timestamps
- For one to many relations, foreign keys are to be specified using "constrained" as such:
$table->foreignId('other_id')->constrained()->onDelete('cascade');
- All views must have Blade templating to extend the base layout.
- There is to be no mixing of PHP with HTML in the views
- Store all text in resources/lang
- Always use getters for parameter acquisition in classes
- Use @csrf in forms
- All routes must be associated with a controller, rather than specifying the function in the routes file.
- All routes must have a single resposibility, and there cannot be two routes with the same name but different method (GET, POST)
- The paths to each controller must be specified after imports as constants
- Route names must be associated to controller names
- https://www.php-fig.org/psr/psr-12/
- https://google.github.io/styleguide/htmlcssguide.html
- https://www.freecodecamp.org/news/snake-case-vs-camel-case-vs-pascal-case-vs-kebab-case-whats-the-difference/
- https://laravel.com/docs/12.x/blade
- https://w3schools.tech/tutorial/laravel/laravel_blade_templates
- https://www.w3schools.com/js/js_conventions.asp
- Class presentations and classes