I have some Categories. When I will click on a category, then all of it's sub categories will be shown in a Bootstrap Modal.
<p data-toggle="modal" data-id="{{$category['id']}}" data-target="#subcategory_Modal">{{$category['name']}}</p>
I am passing the category id with data-id
. Main Category has parent id 0. And sub category has a value of parent_id.
Now, How can I compare my passing ID: data-id
with the parent_id which I am getting from database with Laravel/PHP.
@foreach($categories as $category)
@if(!empty($category['sub_categories']))
@foreach($category['sub_categories'] as $sc)
@php($parent_id_of_sc = $sc['parent_id'])
@if($parent_id_of_sc==id) //like this
<p><button>{{$sc['name']}}</button></p>
@endif
@endforeach
@endif
@endforeach
Please check my code. I am getting all parent ids from this loop.I have to compare with the Modal Data ID which I have passed with Modal.