category filters

This commit is contained in:
merdan 2022-02-01 14:35:16 +05:00
parent 45648904a8
commit 1f277be89c
2 changed files with 12 additions and 0 deletions

View File

@ -3,6 +3,7 @@
namespace Sarga\API\Http\Controllers;
use App\Http\Controllers\Controller;
use Sarga\API\Http\Resources\Catalog\Attribute;
use Sarga\API\Http\Resources\Catalog\Category;
use Sarga\Shop\Repositories\CategoryRepository;
@ -33,4 +34,14 @@ class Categories extends Controller
}
public function filters($id){
$category = $this->categoryRepository->with('filterableAttributes')->find($id);
if($category)
return Attribute::collection($category->filterableAttributes);
else{
return response()->json(['error'=>'not found'],404);
}
}
}

View File

@ -33,6 +33,7 @@ Route::group(['prefix' => 'api'], function ($router) {
'repository' => CategoryRepository::class,
'resource' => Category::class,
])->name('api.categories');
Route::get('categories/{id}/filters',[Categories::class,'filters']);
//attributes by code
Route::get('attribute-options', [ResourceController::class, 'index'])->defaults('_config', [
'repository' => AttributeOptionRepository::class,