Laravel - how to get file path

In Laravel im using this code in my controller to get files from directory:

public function galleryImages($album) {

    $images = File::allFiles('gallery/'.$album);
    return View::make('galleryimages', ['images' => $images]);
}

      

and in my view "gallery":

    @foreach($images as $image)

        <img src="???">  <-- how to get file url here?

    @endforeach

      

Now how can I get the pathName of the $ image variable? The Var_dump of the $ image is returned:

object(Symfony\Component\Finder\SplFileInfo)#247 (4) {
["relativePath":"Symfony\Component\Finder\SplFileInfo":private]=> string(0) "" 
["relativePathname":"Symfony\Component\Finder\SplFileInfo":private]=> string(11) "garden5.jpg" 
["pathName":"SplFileInfo":private]=> string(25) "gallery/Album/garden5.jpg" 
["fileName":"SplFileInfo":private]=> string(11) "garden5.jpg" } 

      

I tried to use $ image-> pathName but it doesn't work.

+3


source to share


1 answer


You have to use getter method

$image->getPathname()

      



The Symfony class extends from SplFileInfo

. You can find a link to all of its methods at php.net

+6


source







All Articles