public function getSubCategory(Request $request)
{
$response = array();
try {
$categories = Category::where(['status' => 0, 'parent_id' => 0])- >get();
$subCategory = Category::where('status', 0)->where('parent_id', '!=', 0)->get();
foreach ($subCategory as $sub) {
$categoryTitle = Category::where(['id' => $sub->parent_id])- >get(['title']);
$result[] = array(
'cat_title' => $categoryTitle[0]->title,
'sub_title' => $sub->title,
);
}
if (count($result) > 0) {
$response = (new ApiMessageController())->successResponse($result, "Categories List Found!");
} else {
$response = (new ApiMessageController())->failedresponse("No Categories List Found");
}
} catch (\Illuminate\Database\QueryException $ex) {
$response = (new ApiMessageController())->queryexception($ex);
}
return $response;
}
I will like to display parent category and its children under it. Something:
- Category 1
- Sub 1
- Sub 2
- Category 2
- Sub 1
- Sub 2
i want to show data like see demo
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire