Support the ongoing development of Laravel.io →
Views Blade Validation
Last updated 2 years ago.
0

The problem is your double @foreach which will result in count($info) x count($books) results. This is why you see 28 outputs with 4 of those being a match ( "Book" )

0

Good to know, what should i do to fix this problem? Any idea Thanks

0

this might be a viable solution for you.

// create an array of book names
$bookNames = $books->pluck('name');

// loop over the files you have
@foreach($info as $file)
    // is filename in your book array
    @if(in_array($file, $books) )
        <p>Book</p>
    @else
         <p>No Book</p> 
    @endif
@endforeach

Last updated 8 years ago.
0

Thanks for your answer but its not working just gettin No book 7 times

$bookNames[] = $books->pluck('name');

// loop over the files you have
@foreach($info as $file)
    // is filename in your book array
    @if(in_array($file, $booksNames) )
        <p>Book</p>
    @else
         <p>No Book</p> 
    @endif
@endforeach

And i tried but its not working

<?php
  $bookNames[] = $archivos->pluck('name');
  //dd(count($bookNames[0]));
  $i = 0;
 ?>


  // loop over the files you have
  @foreach($info as $file)
      // is filename in your book array
      <?php $i++; ?>
        @if(($i< count($bookNames[0]))?($file['filename'] == $bookNames[0][$i]):true )
            <p>Book</p>
        @else
             <p>No Book</p>
        @endif

  @endforeach
Last updated 8 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

eliogsolis eliogsolis Joined 15 Jul 2016

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.