completed clean sub categories

This commit is contained in:
vedatakd 2021-03-05 17:44:27 +03:00
parent ee69934c3d
commit cd9a416ff1
2 changed files with 12 additions and 16 deletions

View File

@ -117,7 +117,7 @@ class CategoryRepository extends EntryRepository implements CategoryRepositoryIn
public function getDeletedCategories()
{
return $this->newQuery()->whereNotNull('deleted_at')->get();
return $this->model->withTrashed()->newQuery()->whereNotNull('deleted_at')->get();
}
public function getMainAndSubCats()

View File

@ -213,21 +213,17 @@ class CategoryController extends AdminController
public function cleanSubCategories()
{
// $cats = $this->categoryRepository->getDeletedCategories();
//
// $delete_category_keys = $cats->pluck('id');
//
// dd($delete_category_keys);
//
// foreach ($cats as $cat) {
// $parentCatId = $cat->parent_category_id;
// $parentCat = $this->categoryRepository->find($parentCatId);
// if (is_null($parentCat) && !is_null($parentCatId)) {
// $this->categoryEntryTranslationsModel->where('entry_id', $cat->id)->delete();
// //Todo Sub Categories
// $deletedCatsCount++;
// }
// }
$sub_c = 1;
for ($i = 0; $i <= $sub_c; $i++) {
$cats = $this->categoryRepository->getDeletedCategories();
$delete_category_keys = $cats->pluck('id')->all();
$query_delete = $this->categoryRepository->newQuery()->whereIn('parent_category_id', $delete_category_keys);
if ($query_delete->count()) {
$query_delete->delete();
$sub_c++;
}
}
return redirect('admin/cats');
}