Answers for "how can we manage category and product in laravek"

0

how can we manage category and product in laravek

| id    | parent_id     | name          |
|----   |-----------    |-------------  |
| 1     | NULL          | Electronics   |
| 2     | 1             | Computers     |
| 3     | 2             | Accessories   |
| 4     | 3             | Keyboards     |
Posted by: Guest on May-06-2021
0

how can we manage category and product in laravek

public function categories() {
    return $this->belongsTo(Category::class, 'category_id');
}
Posted by: Guest on May-06-2021
0

how can we manage category and product in laravek

| id    | category_id   | name          |
|----   |-------------  |-----------    |
| 1     | 2             | Product 1     |
| 2     | 3             | Product 2     |
| 3     | 4             | Product 3     |
Posted by: Guest on May-06-2021
0

how can we manage category and product in laravek

public function parent() {
    return $this->belongsTo(Category::class, 'parent_id');
}

public function childs() {
    return $this->hasMany(Category::class, 'parent_id');
}

public function products() {
    return $this->hasManyThrough(Product::class, Category::class, 'parent_id', 'category_id', 'id');
}
Posted by: Guest on May-06-2021

Code answers related to "how can we manage category and product in laravek"

Browse Popular Code Answers by Language