Skip to content

Commit

Permalink
Merge pull request #159 from avored/developed
Browse files Browse the repository at this point in the history
Developed
  • Loading branch information
indpurvesh authored Oct 30, 2020
2 parents af0f95a + 884cf1d commit d9bd8ff
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 6 deletions.
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AvoredFrameworkSchema318 extends Migration
{
/**
* @todo arrange Database Table Creation and foreign keys
* Install the AvoRed Address Module Schema.
*
* @return void
*/
public function up()
{
Schema::table('categories', function (Blueprint $table) {
$table->unsignedBigInteger('parent_id')->nullable();
$table->foreign('parent_id')->references('id')->on('categories');
});

}

/**
* Uninstall the AvoRed Address Module Schema.
*
* @return void
*/
public function down()
{
Schema::table('categories', function (Blueprint $table) {
$table->dropForeign('categories_parent_id_foreign');
$table->dropColumn('parent_id');
});
}
}
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
1 change: 1 addition & 0 deletions resources/lang/en/system.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
],
],

'parent_id' => 'Parent ID',
'customer_group' => 'Customer Group',
'failed' => 'These credentials do not match our records.',
'password' => 'Passwords must be at least eight characters and match the confirmation.',
Expand Down
14 changes: 13 additions & 1 deletion resources/views/catalog/category/_fields.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
<div class="mt-3 flex w-full">
<div class="flex w-full">
<avored-select
label-text="{{ __('avored::system.parent_id') }}"
field-name="parent_id"
:options="{{ $categoryOptions }}"
init-value="{{ $category->parent_id ?? '' }}"
error-text="{{ $errors->first('parent_id') }}"
:has-empty="true"
>
</avored-select>
</div>

<div class="flex w-full">
<avored-input
label-text="{{ __('avored::system.fields.name') }}"
field-name="name"
Expand Down
2 changes: 1 addition & 1 deletion resources/views/layouts/app.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

</div></avored-layout>
</div>
@if(env('APP_ENV') === 'testing' && false)
@if(env('APP_ENV') === 'testing' && file_exists(public_path('mix-manifest.json')))
<script src="{{ mix('/vendor/avored/js/avored.js') }}"></script>
@push('scripts')
<script src="{{ mix('/vendor/avored/js/app.js') }}"></script>
Expand Down
14 changes: 11 additions & 3 deletions 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 All @@ -44,10 +46,11 @@ public function index()
*/
public function create()
{
$categoryOptions = $this->categoryRepository->options();
$tabs = Tab::get('catalog.category');

return view('avored::catalog.category.create')
->with(compact('tabs'));
->with(compact('tabs', 'categoryOptions'));
}

/**
Expand All @@ -73,10 +76,15 @@ public function store(CategoryRequest $request)
*/
public function edit(Category $category)
{
$categoryOptions = $this->categoryRepository
->options()
->filter(function ($option) use ($category) {
return $option !== $category->name;
});
$tabs = Tab::get('catalog.category');

return view('avored::catalog.category.edit')
->with(compact('category', 'tabs'));
->with(compact('category', 'tabs', 'categoryOptions'));
}

/**
Expand Down
26 changes: 25 additions & 1 deletion src/Database/Models/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ class Category extends BaseModel
* The attributes that are mass assignable.
* @var array
*/
protected $fillable = ['name', 'slug', 'meta_title', 'meta_description'];
protected $fillable = [
'name',
'slug',
'meta_title',
'meta_description',
'parent_id'
];

/**
* Category belongs to many products.
Expand All @@ -18,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 d9bd8ff

Please sign in to comment.