Skip to content

Commit

Permalink
Added a parent id into category table
Browse files Browse the repository at this point in the history
  • Loading branch information
indpurvesh committed Oct 30, 2020
1 parent d5aaa1c commit 11c3697
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions config/avored.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

return [
'admin_url' => 'admin',
'admin_api_url' => 'admin/api',
'symlink_storage_folder' => 'storage',
'cart' => ['session_key' => 'cart_products', 'promotion_key' => 'cart_discount'],
'model' => [
Expand Down
8 changes: 8 additions & 0 deletions resources/components/catalog/category/CategoryTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
{{ item.name }}
</a>
</template>
<template slot="parent" slot-scope="{item}">
{{ item.parent ? item.parent.name : '' }}
</template>
<template slot="action" slot-scope="{item}">
<div class="flex items-center">
<a :href="getEditUrl(item)">
Expand Down Expand Up @@ -57,6 +60,11 @@ export default {
fieldKey: "id",
visible: true
},
{
label: this.$t('system.parent'),
slotName: "parent",
visible: true
},
{
label: this.$t('system.name'),
slotName: "name",
Expand Down
1 change: 1 addition & 0 deletions resources/js/modules/system/lang/en.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"id": "ID",
"parent": "Parent",
"name": "Name",
"slug": "Slug",
"actions": "Actions",
Expand Down
4 changes: 3 additions & 1 deletion src/Catalog/Controllers/CategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ public function __construct(
*/
public function index()
{
$categories = $this->categoryRepository->paginate();
$perPage = 10;
$with = ['parent'];
$categories = $this->categoryRepository->paginate($perPage, $with);

return view('avored::catalog.category.index')
->with(compact('categories'));
Expand Down
18 changes: 18 additions & 0 deletions src/Database/Models/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,22 @@ public function products()
{
return $this->belongsToMany(Product::class);
}

/**
* Category can has many child categories.
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function children()
{
return $this->hasMany(self::class, 'parent_id');
}

/**
* Category can have one parent category.
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function parent()
{
return $this->belongsTo(self::class, 'parent_id');
}
}

0 comments on commit 11c3697

Please sign in to comment.