灯箱与Laravel

I'm trying to get lightbox working with the Laravel framework and It's a bit tricky and thought I'd ask for suggestions here. The goal is to have 1 clickable image on the page that in turn has a link with an array of the rest of the images for lightbox.

Here's my method:

public function singleproperty(Properties $property)
    {
         $images = File::Files('images/property/' . $property->MLS_No);
         $singleImage = reset($images);
         return View::make('SingleProperty', compact('property', 'singleImage', 'images'));
     }

Here's my view:

@foreach($images as $images)
        <a href= "../{{ $images }}" rel='lightbox[image]' >
    {{HTML::image("$singleImage",  $alt='image', array('width' => '400') ) }}</a>

        @endforeach

I used reset() in thee method in an attempt to only get the first image in the directory, which works, but gets the first image x the amount of images in the directory. Not what I'm looking for. Also I can remove the foreach loop in the view and get just the first image, but then lightbox can't find any of the images and will not work.

Also, I tried using an absolute value on the CSS wrapper, which works, but it gets the last image first which also isn't what I'm looking for.

Any ideas how I could solve this?

3 things:

  1. @foreach($images as $images) can be problematic, you are telling PHP to loop $images but also use that same variable as individual item in that array. Try change it to @foreach($images as $image).

  2. Your $singleImage contains the first image only. So when you do {{HTML::image("$singleImage", ... }} you'll always get the first image no matter how you loop. Try change that to {{HTML::image("$image", ... }}.

  3. If I understand correctly, only the first image should be shown, while the rest need to be in the page in order for the lightbox to work. So I believe you could put the images in the page, but hide them. For example:

In your view:

$firstImage = true;

@foreach($images as $images)
    <a href="../{{ $image }}" rel="lightbox[image]" {{ $firstImage ? 'style="display: none"':'' }}>
        {{HTML::image("$image",  $alt="image", array("width" => 400)) }}
    </a>
    <?php $firstImage = false; ?>
@endforeach