2. Final Report Tasniflagich


Download 3.88 Mb.
Pdf ko'rish
bet12/15
Sana25.07.2023
Hajmi3.88 Mb.
#1662428
1   ...   7   8   9   10   11   12   13   14   15
Bog'liq
2.Final Report Tasniflagich

3.4.3 Implementation
To The realization of models of the 4 tables we need to create Classes extended by Model
class which are provided by Eloquent ORM.
3.4.3.1 Category
To create category model we run command in console:
php artisan make:model Category -m
Then in app/Category.php we create relation methods:
1. products - to get all products of category
2. parent - to get parent of category
3. childrens - to get all childrens of category
Figure 12. Category model, relation methods
As we can see in Figure 12 there are special methods of the Eloquent Model class such as
“hasMany” and “belongsTo” to define many-to-one or one-to-many relations respectively.
The “-m” flag in the run command is dedicated to creation of the migration file of the new
model. In folder database/migrations we can see file {date}_create_categories_table.php
In the CreateCategoriesTable class’s method, we should fill table columns. At the end it should
look like in Figure 13. As you can see there are special methods to map the column types such
as bigIncrements, integer, string, foreignm sofDeletes, timestamps.
TTPU
20
2022


Figure 13. Category migration file
3.4.3.1 Product
To create product model we run command in console:
php artisan make:model Product -m
Then in app/Product .php we create relation methods:
1. fields - to get all fields of product
2. category - to get category of product
3. root_category - to get second order category from top of product
4. unit - to get category of product
5. expenditure - to get category of product
At the end the created model should be similar to Figure 14.
TTPU
21
2022


Figure 14. Product model, relation methods
Same as Category we should set up a migration file {date}_create_products_table.php as in
Figure 15. We can mention Product model has large amount of foreign keys and relations
methods in the category model comparison.
TTPU
22
2022


Figure 15. Product model migration file
3.4.3.1 Fields
To create field model we run command in console:
php artisan make:model Field -m
Then in app/Field.php we create relation methods:
1. values- to get all values of field
2. product - to get product of field
At the end the created model should be similar to Figure 16.
TTPU
23
2022


Figure 16. Fields model, relations
Same as Category and Product we should set up a migration file {date}_create_fields_table.php
as in Figure 17.
Figure 17. Field mode, migration file
TTPU
24
2022



Download 3.88 Mb.

Do'stlaringiz bilan baham:
1   ...   7   8   9   10   11   12   13   14   15




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling