Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
belguinan committed Nov 10, 2018
1 parent 03062dd commit a2846ec
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
13 changes: 12 additions & 1 deletion app/Shop/Categories/Repositories/CategoryRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,23 @@ public function updateCategory(array $params) : Category
}

$merge = $collection->merge(compact('slug', 'cover'));
if (isset($params['parent'])) {

// set parent attribute default value if not set
$params['parent'] = $params['parent'] ?? 0;

// If parent category is not set on update
// just make current category as root
// else we need to find the parent
// and associate it as child
if ( (int)$params['parent'] == 0) {
$category->saveAsRoot();
} else {
$parent = $this->findCategoryById($params['parent']);
$category->parent()->associate($parent);
}

$category->update($merge->all());

return $category;
}

Expand Down
1 change: 1 addition & 0 deletions resources/views/admin/categories/create.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<div class="form-group">
<label for="parent">Parent Category</label>
<select name="parent" id="parent" class="form-control select2">
<option value="">-- Select --</option>
@foreach($categories as $category)
<option value="{{ $category->id }}">{{ $category->name }}</option>
@endforeach
Expand Down
1 change: 1 addition & 0 deletions resources/views/admin/categories/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<div class="form-group">
<label for="parent">Parent Category</label>
<select name="parent" id="parent" class="form-control select2">
<option value="0">No parent</option>
@foreach($categories as $cat)
<option @if($cat->id == $category->parent_id) selected="selected" @endif value="{{$cat->id}}">{{$cat->name}}</option>
@endforeach
Expand Down

0 comments on commit a2846ec

Please sign in to comment.