Skip to content

Commit 7019130

Browse files
committed
Add getCategoriesWithAttributes method and corresponding API route
This commit introduces a new method in the ListCategoryController to retrieve categories along with their associated attributes from the database. Additionally, a new route is added to the API for accessing this method, enhancing the category management functionality and providing more detailed category information.
1 parent aec8066 commit 7019130

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

app/Http/Controllers/ListCategoryController.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use App\Models\Gender;
66
use App\Models\Category;
77
use Illuminate\Http\Request;
8+
use Illuminate\Support\Facades\DB;
89
use Illuminate\Support\Facades\Cache;
910
use App\Http\Resources\CategoryResource;
1011

@@ -101,4 +102,15 @@ public function getCategoriesByGender($parentCategoryId) {
101102
return response()->json($categoriesByGender);
102103
}
103104

105+
public function getCategoriesWithAttributes(){
106+
107+
$categoriesWithAttributes=DB::table('categories')
108+
->join('category_atributes','categories.id','=','category_atributes.category_id')
109+
->join('attributes','category_atributes.attribute_id','attributes.id')
110+
->select('categories.id as category_id','categories.category_name as category_name','attributes.id as attribute_id','attributes.attributes_name as attribute_name')
111+
->get();
112+
113+
return $categoriesWithAttributes;
114+
}
115+
104116
}

routes/api.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
*/
112112

113113

114-
114+
Route::get('/categories/attributes',[ListCategoryController::class,"getCategoriesWithAttributes"]);
115115
Route::get("catalogue/{shop_key}",[CatalogueController::class,'index']);
116116

117117
Route::get('/filter/products/{arrayId}',[CategoryFilterController::class,'filter']);

0 commit comments

Comments
 (0)