Skip to content

Commit

Permalink
added a parent_id into category crud
Browse files Browse the repository at this point in the history
  • Loading branch information
indpurvesh committed Oct 25, 2020
1 parent 557bd38 commit d5aaa1c
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 4 deletions.
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');
});
}
}
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
10 changes: 8 additions & 2 deletions src/Catalog/Controllers/CategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,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 +74,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
8 changes: 7 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 Down

0 comments on commit d5aaa1c

Please sign in to comment.