2. Final Report Tasniflagich
Download 3.88 Mb. Pdf ko'rish
|
2.Final Report Tasniflagich
- Bu sahifa navigatsiya:
- 3.5 Controllers 3.5.1 Introductions to controllers
- 3.5.2 Pattern and principles 3.5.2.1 DRY implementation
3.4.3.1 Field values
To create field value model we run command in console: php artisan make:model FieldValue -m Then in app/FieldValue.php we create relation methods: 1. field- to get all values of field At the end the created model should be similar to Figure 18. and migration file in Figure 19. Figure 18. Field value model’s relation Figure 19. Field value model’s migration TTPU 25 2022 3.5 Controllers 3.5.1 Introductions to controllers Controllers can group related request handling logic into a single class. There 3 type of controller: 1. Single actions controller 2. Resource controller 3. Custom controller Single action controllers consist of only __invoke methods in class. Resource controllers by default have 7 methods represented in Table 2 with example of category. Custom controllers are empty by default. Table 2. resource controller methods and other parameters Verb URI Method Route Name GET /category index category.index GET /category/create create category.create POST /category store category.store GET /category/{id} show category.show GET /category/{id}/edit edit category.edit PUT/PATCH /category/{id} update category.update DELETE /category/{id} destroy category.destroy Laravel has a special command to create controllers in the console via artisan. Figure 20. Command to create controller TTPU 26 2022 3.5.2 Pattern and principles 3.5.2.1 DRY implementation DRY, which stands for ‘don’t repeat yourself,’ is a principle of software development that aims at reducing the repetition of patterns and code duplication in favor of abstractions and avoiding redundancy. Before implementing the logic of record manipulation (creating, editing, deleting) there was a feature to accept action or decline. in order to follow DRY principle we decided to create a helper function that saves the state of request before moving on. Figure 21 represents a function which accepts request data, action name, possible response to the user and request data from the url. Also as you can see the created helper acquires requests which are validated before, in order to decrease error from given function. Nice to mention usage of database transitions in order to prevent zombie data in the database, if errors happened in the middle of database insertion. Download 3.88 Mb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling