@Snapey one thing i forgot to tell you sorry using the <div> tag i have applied javascript to show the list attributes as soon as the Subcategory drop down is selected so i need the tag inside the loop
below is code sir
public function addProducts(){
$subcat = DB::table('categories')->select('*')->where('parent_id','!=',NULL)->get();
$attr = DB::table('attributes')->select('*')->get();
return view ('addproduct',compact('subcat','attr'));
}
blade template
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="col-xs-6 col-sm-6 col-md-6">
<div class="form-group">
<strong>Select SubCategory:</strong>
<select required class="selectpicker" name ="parent_id" id="parent_id">
<option value="" ></option>
@foreach ( $subcat as $subcats)
<option value="{{ $subcats->parent_id }}"> {{ $subcats->name }}
</option>
@endforeach
</select>
@foreach($attr as $attrs)
<div class="some" id="some_{{ $attrs->category_id }}" style="display:none;">
<strong>{{ $attrs->attribute_1 }}<strong><br>
{!! Form::text('attvalue_1', null, array('placeholder' => '','class' => 'form-control')) !!}<br>
<strong>{{ $attrs->attribute_2 }}<strong><br>
{!! Form::text('attrvalue_2', null, array('placeholder' => '','class' => 'form-control')) !!}<br>
@endforeach
</div>
</div>
</div>
</div>
</div>
<script>
$('#parent_id').on('change',function(){
$(".some").hide();
var some = $(this).find('option:selected').val();
$("#some_" + some).show();
});
</script>