Fixed category display error from documentation. Previously, I showed all categories of documentation.
This commit is contained in:
		@@ -11,7 +11,6 @@ use App\Services\Search\CreateSearchInstanceCommand;
 | 
				
			|||||||
use App\Dto\Builder\DocumentationCategory as DocumentationCategoryBuilderDto;
 | 
					use App\Dto\Builder\DocumentationCategory as DocumentationCategoryBuilderDto;
 | 
				
			||||||
use Illuminate\Database\Eloquent\Builder;
 | 
					use Illuminate\Database\Eloquent\Builder;
 | 
				
			||||||
use Illuminate\Database\Eloquent\Relations\HasOne;
 | 
					use Illuminate\Database\Eloquent\Relations\HasOne;
 | 
				
			||||||
use Illuminate\Support\Collection;
 | 
					 | 
				
			||||||
use Illuminate\Support\Str;
 | 
					use Illuminate\Support\Str;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
final readonly class DocumentationCategoryRepository
 | 
					final readonly class DocumentationCategoryRepository
 | 
				
			||||||
@@ -63,7 +62,7 @@ final readonly class DocumentationCategoryRepository
 | 
				
			|||||||
            ->exists();
 | 
					            ->exists();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function getForSelect(?ProjectLanguage $defaultLanguage, ?DocumentationCategory $exceptCategory = null, array $withExcepts = []): array
 | 
					    public function getForSelect(DocumentationVersion $version, ?ProjectLanguage $defaultLanguage, ?DocumentationCategory $exceptCategory = null, array $withExcepts = []): array
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $with = [
 | 
					        $with = [
 | 
				
			||||||
            'content' => function (HasOne $hasOne) use ($defaultLanguage) {
 | 
					            'content' => function (HasOne $hasOne) use ($defaultLanguage) {
 | 
				
			||||||
@@ -73,7 +72,7 @@ final readonly class DocumentationCategoryRepository
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
        ];
 | 
					        ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $categories = DocumentationCategory::query()
 | 
					        $categories = $version->categories()
 | 
				
			||||||
            ->with($with)
 | 
					            ->with($with)
 | 
				
			||||||
            ->when($exceptCategory, function (Builder $query, DocumentationCategory $exceptCategory) {
 | 
					            ->when($exceptCategory, function (Builder $query, DocumentationCategory $exceptCategory) {
 | 
				
			||||||
                $query->whereNotIn(
 | 
					                $query->whereNotIn(
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -89,7 +89,7 @@ final class DocumentationCategoryService extends Service
 | 
				
			|||||||
            'version'  => $version,
 | 
					            'version'  => $version,
 | 
				
			||||||
            'project'  => $project,
 | 
					            'project'  => $project,
 | 
				
			||||||
            'category' => new DocumentationCategory(),
 | 
					            'category' => new DocumentationCategory(),
 | 
				
			||||||
            'categories' => $this->documentationCategoryRepository->getForSelect($defaultLanguage),
 | 
					            'categories' => $this->documentationCategoryRepository->getForSelect($version, $defaultLanguage),
 | 
				
			||||||
        ]);
 | 
					        ]);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -119,7 +119,7 @@ final class DocumentationCategoryService extends Service
 | 
				
			|||||||
            'version'  => $version,
 | 
					            'version'  => $version,
 | 
				
			||||||
            'project'  => $project,
 | 
					            'project'  => $project,
 | 
				
			||||||
            'category' => $category,
 | 
					            'category' => $category,
 | 
				
			||||||
            'categories' => $this->documentationCategoryRepository->getForSelect($defaultLanguage, $category, $withCategories),
 | 
					            'categories' => $this->documentationCategoryRepository->getForSelect($version, $defaultLanguage, $category, $withCategories),
 | 
				
			||||||
        ]);
 | 
					        ]);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,13 +5,13 @@ namespace App\Services\Admin\Project;
 | 
				
			|||||||
use App\Dto\Builder\Documentation as DocumentationBuilderDto;
 | 
					use App\Dto\Builder\Documentation as DocumentationBuilderDto;
 | 
				
			||||||
use App\Dto\QuerySettingsDto;
 | 
					use App\Dto\QuerySettingsDto;
 | 
				
			||||||
use App\Dto\Service\Admin\Project\Documentation\StoreUpdate;
 | 
					use App\Dto\Service\Admin\Project\Documentation\StoreUpdate;
 | 
				
			||||||
 | 
					use App\Exceptions\Services\DocumentationContent\StorageCommandException;
 | 
				
			||||||
use App\Models\Documentation;
 | 
					use App\Models\Documentation;
 | 
				
			||||||
use App\Models\ProjectLanguage;
 | 
					use App\Models\ProjectLanguage;
 | 
				
			||||||
use App\Models\User;
 | 
					use App\Models\User;
 | 
				
			||||||
use App\Repositories\DocumentationCategoryRepository;
 | 
					use App\Repositories\DocumentationCategoryRepository;
 | 
				
			||||||
use App\Repositories\DocumentationRepository;
 | 
					use App\Repositories\DocumentationRepository;
 | 
				
			||||||
use App\Repositories\DocumentationVersionRepository;
 | 
					use App\Repositories\DocumentationVersionRepository;
 | 
				
			||||||
use App\Repositories\ProjectRepository;
 | 
					 | 
				
			||||||
use App\ServiceResults\ServiceResultArray;
 | 
					use App\ServiceResults\ServiceResultArray;
 | 
				
			||||||
use App\ServiceResults\ServiceResultError;
 | 
					use App\ServiceResults\ServiceResultError;
 | 
				
			||||||
use App\ServiceResults\ServiceResultSuccess;
 | 
					use App\ServiceResults\ServiceResultSuccess;
 | 
				
			||||||
@@ -89,7 +89,7 @@ final class DocumentationService extends Service
 | 
				
			|||||||
            'version' => $version,
 | 
					            'version' => $version,
 | 
				
			||||||
            'project' => $project,
 | 
					            'project' => $project,
 | 
				
			||||||
            'documentation' => new Documentation(),
 | 
					            'documentation' => new Documentation(),
 | 
				
			||||||
            'categories' => $this->documentationCategoryRepository->getForSelect($defaultLanguage),
 | 
					            'categories' => $this->documentationCategoryRepository->getForSelect($version, $defaultLanguage),
 | 
				
			||||||
        ]);
 | 
					        ]);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -119,7 +119,7 @@ final class DocumentationService extends Service
 | 
				
			|||||||
            'version' => $version,
 | 
					            'version' => $version,
 | 
				
			||||||
            'project' => $project,
 | 
					            'project' => $project,
 | 
				
			||||||
            'documentation' => $documentation,
 | 
					            'documentation' => $documentation,
 | 
				
			||||||
            'categories' => $this->documentationCategoryRepository->getForSelect($defaultLanguage, null, $withCategories),
 | 
					            'categories' => $this->documentationCategoryRepository->getForSelect($version, $defaultLanguage, null, $withCategories),
 | 
				
			||||||
        ]);
 | 
					        ]);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -150,6 +150,8 @@ final class DocumentationService extends Service
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                return $documentation;
 | 
					                return $documentation;
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
 | 
					        } catch (StorageCommandException $e) {
 | 
				
			||||||
 | 
					            return $e->getResultError();
 | 
				
			||||||
        } catch (\Throwable $e) {
 | 
					        } catch (\Throwable $e) {
 | 
				
			||||||
            report($e);
 | 
					            report($e);
 | 
				
			||||||
            return $this->errService(__('Server Error'));
 | 
					            return $this->errService(__('Server Error'));
 | 
				
			||||||
@@ -190,6 +192,8 @@ final class DocumentationService extends Service
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                return $documentation;
 | 
					                return $documentation;
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
 | 
					        } catch (StorageCommandException $e) {
 | 
				
			||||||
 | 
					            return $e->getResultError();
 | 
				
			||||||
        } catch (\Throwable $e) {
 | 
					        } catch (\Throwable $e) {
 | 
				
			||||||
            report($e);
 | 
					            report($e);
 | 
				
			||||||
            return $this->errService(__('Server Error'));
 | 
					            return $this->errService(__('Server Error'));
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user