0

I'm doing a upload many file and trying pass param to get message within for loop, how I can send param index to blade {{__()}}

I try do below, input work but label doesn't work: {{__('cha_content.attach1_{{$i}}]')}}

in blade file:

@for ($i = 1; $i <= 11; $i++)
    <div class="form-group row">
        <label class="col-sm-3 col-form-label font-weight-bold text-right">{{__('cha_content.attach1_{{$i}}]')}}</label>
        <div class="col-sm-6">
            <input class="form-control" type="file" id="attach1_{{ $i }}" name="attach1_{{ $i }}">
        </div>
    </div>
@endfor

in lang file:

<?php
return [
    'attach1_1'=>'1. Plan report',
    'attach1_2'=>'2. Cancelation report',
    'attach1_3'=>'3. Daily report',
    'attach1_4'=>'4. Process report',
    'attach1_5'=>'5. Site Specific',
    'attach1_6'=>'6. Visitor Log',
    'attach1_7'=>'7. Deployment plan',
    'attach1_8'=>'8. ...',
    'attach1_9'=>'9. ...',
    'attach1_10'=>'10. ...',
    'attach1_11'=>'11. ...',
    ...

my result: (https://i.stack.imgur.com/Uestc.png)

  • 1
    PHP supports arrays for HTML forms including for file-uploads. Why not consider them? It then automatically does the indexes of the array and you don't need to implement it specifically both in the template as in the processing. Just an idea. – hakre Dec 09 '22 at 07:38
  • It would be more logical to follow a method as @hakre said about uploading multiple files with PHP. For that, you can check out this post: https://stackoverflow.com/questions/2704314/multiple-file-upload-in-php – cengsemihsahin Dec 09 '22 at 07:44
  • Thanks u, I know mutil file but I need to know what file to save and exactly where it shows, example: Plan report, Daily report,... will show in a tab report, some files will show in other. – Hoang Nguyen Dec 09 '22 at 07:52

1 Answers1

0

Takes a string value inside the __($param) expression. It will be enough to specify that string value.

With this way:

{{__('cha_content.attach1_' . $i)}}
cengsemihsahin
  • 921
  • 2
  • 8
  • 21
  • 1
    IMHO a link to the official documentation plus a little bit of explanation would move it from comment territory towards the answer field. Otherwise it creates the impression it was just a typo in the questions' code and may not be accepted as fitting QA material all-in-all. – hakre Dec 09 '22 at 07:39