Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [Laravel][PHP]Tabel i id rekordu
Puchatek320
post 8.07.2020, 21:37:49
Post #1





Grupa: Zarejestrowani
Postów: 68
Pomógł: 0
Dołączył: 4.11.2019

Ostrzeżenie: (0%)
-----


Cześć,
Mam dość proste pytanie mianowicie mam taki kod

  1. $directory = "../storage/app/backup_films/";
  2. $filecount = 0;
  3. $files = glob($directory . "*");
  4.  
  5. if ($files){
  6. $filecount = count($files);
  7. }
  8.  
  9. foreach(new \DirectoryIterator($directory) as $file)
  10. if(!$file->isDot())
  11.  
  12.  
  13. @foreach ($file as $file )
  14. @if(!$file->isDot())
  15. <tr>
  16. <th scope="row"></th>
  17. <td>
  18. {{$file}}
  19. </td>
  20. <td>
  21. <button type="button" class="btn btn-danger" data-toggle="modal" data-target="#delete_">Usuń</button>
  22. </td>
  23. </tr>
  24. @endif
  25. @endforeach
  26.  
  27. $count_files = $filecount;
  28. return view('admin.admin_db', compact('count_files', 'file'));
  29.  


  1.  
  2. for ($i = 0; $i <= $count_files; $i++) {
  3. echo $i;
  4. }
  5.  

Chciałbym się dowiedzieć gdzie dodać pętle for która będzie generować id? próbowałem już dodać w miejscu id ale robi 12345 a chciałbym żeby robiło id w każdym osobno.

Okey, gdyby ktoś był ciekawy jak to zrobić .

  1. <?php $id = 0; ?>
  2. foreach(new \DirectoryIterator($directory) as $file)
  3. if(!$file->isDot())
  4. <?php id++ ?>
  5.  
  6. @foreach ($file as $file )
  7. @if(!$file->isDot())
  8. <tr>
  9. <th scope="row">{{$id}}</th>
  10. <td>
  11. {{$file}}
  12. </td>
  13. <td>
  14. <button type="button" class="btn btn-danger" data-toggle="modal" data-target="#delete_">Usuń</button>
  15. </td>
  16. </tr>
  17. @endif
  18. @endforeach
  19.  


Ten post edytował Puchatek320 8.07.2020, 18:48:08
Go to the top of the page
+Quote Post
mizii
post 9.07.2020, 19:48:13
Post #2





Grupa: Zarejestrowani
Postów: 86
Pomógł: 1
Dołączył: 19.10.2015

Ostrzeżenie: (0%)
-----


Robi Ci 12345 bo wypisujesz po koleji wartosci i = 1 potem i = 2 potem i = 3 ... do 5 bez separacji wyglada to jak 12345
Go to the top of the page
+Quote Post
viking
post 9.07.2020, 19:56:55
Post #3





Grupa: Zarejestrowani
Postów: 6 365
Pomógł: 1114
Dołączył: 30.08.2006

Ostrzeżenie: (0%)
-----


Albo poczytać https://laravel.com/docs/7.x/blade#the-loop-variable Swoją drogą dalej się nie nauczyłeś ze storage korzystać?


--------------------
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 25.04.2024 - 21:54