1

I loop on a Form::label and text but, the name and the label of label and text is bad. Why the name, id is not => t1 t2 t3 .. t10 ?? I write this:

@for ($i = 1; $i < 11; $i++)
                                <?php $item_name = 't' . $i; ?>

                                @if ($uneCategorie->$item_name != null)
                                    <div class="col-lg-3">
                                        <div class="form-group">
                                         {!! Form::label('{{$uneCategorie->$item_name}}', '{{$uneCategorie->$item_name}}') !!}
                                         {!! Form::text('{{$uneCategorie->$item_name}}', null,array('maxlength' => 255, 'class'=>'form-control' )) !!}                        
                                         </div>                        
                                         @if ($errors->has('{{$uneCategorie->$item_name}}'))
                                         <div class="alert alert-danger" role="alert">
                                             <ul>
                                         @foreach ($errors->get('{{$uneCategorie->$item_name}}') as $message) 
                                             <li>{{$message}}</li>
                                         @endforeach
                                         </ul>
                                         </div>
                                         @endif
                                    </div>
                                @endif                                            
 @endfor  

And i've this:

<label for="<?php echo e($uneCategorie->$item_name); ?>">&lt;?php echo e($uneCategorie-&gt;$item_name); ?&gt;</label>
<input maxlength="255" class="form-control" name="<?php echo e($uneCategorie->$item_name); ?>" type="text" id="<?php echo e($uneCategorie->$item_name); ?>">
emeliku
  • 173
  • 1
  • 13

3 Answers3

1

You're doing this $item_name = 't' . $i; to build a name, so you need to use this variable:

{!! Form::label($item_name, $item_name) !!}
{!! Form::text($item_name, null, array('maxlength' => 255, 'class'=>'form-control' )) !!}

Also, remove curly braces.

Alexey Mezenin
  • 158,981
  • 26
  • 290
  • 279
0

Use below code:

@for ($i = 1; $i < 11; $i++)
  <?php $item_name = 't' . $i; ?>

  @if ($item_name != null)
        <div class="col-lg-3">
            <div class="form-group">

                {!! Form::label($item_name, $item_name) !!}
                {!! Form::text($item_name, null, array('maxlength' => 255, 'class'=>'form-control' )) !!}                        
            </div>                        
            @if ($errors->has($item_name))
             <div class="alert alert-danger" role="alert">
                 <ul>
             @foreach ($errors->get($item_name) as $message) 
                 <li>{{$message}}</li>
             @endforeach
             </ul>
             </div>
            @endif
        </div>
  @endif                                            
 @endfor

Read more about How to set PHP variable in blade

Community
  • 1
  • 1
AddWeb Solution Pvt Ltd
  • 21,025
  • 5
  • 26
  • 57
  • i've already tried this and i've: – emeliku Feb 01 '17 at 13:43
  • @emeliku So what `` does print for you? – AddWeb Solution Pvt Ltd Feb 01 '17 at 13:46
  • App\Models\Categorie Object ( [connection:protected] => [table:protected] => [primaryKey:protected] => id [keyType:protected] => int [perPage:protected] => 15 [incrementing] => 1 [timestamps] => 1 [attributes:protected] => Array ( [id] => 4 [nom] => Leurre [t1] => Couleur [t2] => Taille (cm) [t3] => Poids (g) [t4] => Quantité [t5] => [t6] => [t7] => [t8] => [t9] => [t10] => [created_at] => 2017-01-31 16:35:48 [updated_at] => 2017-01-31 16:35:48 ) [original:protected] => Array ( [id] => 4 [nom] => Leurre .... ///// When i've put {{ $uneCategorie->$item_name }} in loop, its work but no in form – emeliku Feb 01 '17 at 13:52
0

You should try it like this:

 $uneCategorie->$item_name{{$i}}

There is no need for php

Onix
  • 2,129
  • 2
  • 17
  • 26