Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Shawdow's avatar

@Snapey sir this what the code that i am using

 @for($i=0; $i<sizeof($attr); $i++)  
        <div class="some" id="some_{{ $attr[$i]->category_id }}" style="display:none;">     
                     <?php $j = $i+1; ?>                    
                    <strong>{{ $attr[$i]->{'attribute_'.$j} }}</strong><br>

        {!! Form::text('attrvalue_'.$j, null, array('placeholder' => '','class' => 'form-control')) !!}<br>
                             
                        @endfor                                           
            </div>     

page source code sir

<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>
                                                     <option  value="1"> Smart Phone 
                                     </option>
                                                     <option  value="1"> Tablets 
                                     </option>
                                                     <option  value="5"> Refrigirator 
                                     </option>
                                   </select>
            
        <div class="some" id="some_1" style="display:none;">     
                                        
                    <strong>Color</strong><br>

        <input placeholder="" class="form-control" name="attrvalue_1" type="text"><br>
                             
                          
        <div class="some" id="some_5" style="display:none;">     
                                        
                    <strong>Color</strong><br>

        <input placeholder="" class="form-control" name="attrvalue_2" type="text"><br>
                             
            </div>     
                          
            </div>                             
            </div>                                            
            </div> 


Shawdow's avatar

@Snapey i think the problem that i am facing would you have understood i think sir. according to your hands on experience in the laravel any suggestion to change the logic i would gladly accept it use Suppose the if my logic is not good!!

Snapey's avatar
Snapey
Best Answer
Level 122

Use this code. When this works, you can simplify it if you don't like repeating the elements.

@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>

    <strong>{{ $attrs->attribute_3 }}<strong><br>
    {!! Form::text('attrvalue_3', null, array('placeholder' => '','class' => 'form-control')) !!}
    <br>

    <strong>{{ $attrs->attribute_4 }}<strong><br>
    {!! Form::text('attrvalue_4', null, array('placeholder' => '','class' => 'form-control')) !!}
    <br>

    <strong>{{ $attrs->attribute_5 }}<strong><br>
    {!! Form::text('attrvalue_5', null, array('placeholder' => '','class' => 'form-control')) !!}
    <br>

    <strong>{{ $attrs->attribute_6 }}<strong><br>
    {!! Form::text('attrvalue_6', null, array('placeholder' => '','class' => 'form-control')) !!}
    <br>

    <strong>{{ $attrs->attribute_7 }}<strong><br>
    {!! Form::text('attrvalue_7, null, array('placeholder' => '','class' => 'form-control')) !!}
    <br>
     
  </div>

@endforeach 
3 likes
shez1983's avatar

i m not sure why no one has suggested this (only read through the first page my mistake after skim-reading 2nd page)

you can move the to outside the foreach...

as an aside your attribute naming looks atrocious (Unless i am mistaken)

Shawdow's avatar

@Snapey now i have used same solution.But using your solution does it works with validating the all the 10 text boxes sir??

Snapey's avatar

repeat for 10 if thats how many attributes you have

We have not previously mentioned validation so I have not a clue whether your choice of field names matches your validation rules

You know, you have to use your own initiative some times.

Shawdow's avatar

@Snapey sir i have used the validation of repeating 10 times like as below it does not work sir. data is filled in the text box click on submit it gives error message attrivalue 1 required why is like this sir.

$this->validate($request,[

         'attrivalue_1' => 'required',
            'attrvalue_2' => 'required',
            'attrvalue_3' => 'required',
            'attrvalue_4' => 'required',
            'attrvalue_5' => 'required',
            'attrvalue_6' => 'required',
            'attrvalue_7' => 'required',
            'attrvalue_8' => 'required',
            'attrvalue_9' => 'required',
            'attrvalue_10' => 'required',
 ]);

Snapey's avatar

Well for starters you have a typo in the name of the attribute

Shawdow's avatar

@Snapey sorry i have tried like below sir it does not work for me

$this->validate($request,[

              'attrvalue_1' => 'required',
            'attrvalue_2' => 'required',
            'attrvalue_3' => 'required',
            'attrvalue_4' => 'required',
            'attrvalue_5' => 'required',
            'attrvalue_6' => 'required',
            'attrvalue_7' => 'required',
            'attrvalue_8' => 'required',
            'attrvalue_9' => 'required',
            'attrvalue_10' => 'required',
 ]);

Snapey's avatar

three pages is enough of this nonsense. Your question was about placement of the div.

I don't know what you are doing with the form, that is a separate issue, however the fact that each set of attributes has the same field names won't help.

Shawdow's avatar

@Snapey thanks for answering to my question from past days sir.sorry i will open new thread for my above problem mark the working solution!!

Previous

Please or to participate in this conversation.