foreach文件图像目录Laravel

时间:2015-07-25 12:23:00

标签: php laravel foreach

我正在学习如何使用Laravel。我刚学会了如何在数据库中为文章做一个foreach循环。现在我想尝试相同但循环我的图像目录中的所有图像。我怎样才能做到这一点?它是否与此相似:

@foreach (File::allFiles(public_path().'/assets/image/') as $file)
{
    $filename = $file->getRelativePathName();
    echo HTML::image('public/assets/img/'.$filename, $filename);
}
@endforeach

同样在我的文章页面中,我能够将foreach应用于li对象,如何为我的图像执行相同的操作?

@foreach($articles as $article)
    <div class="grid-item">
        <li><a href="/article/{{$article->id}}">{{$article->photo}}</a></li>
        <li><a href="/article/{{$article->id}}">{{$article->title}}</a></li>
        {!! Form::open(['url' => 'article' ]) !!}
        {!! Form::file('image', null) !!}

        <div class="form-group">
            {!! Form::hidden('user_id', $article->user_id, ['class' => 'form-control']) !!}
        </div>

        <div class="form-group">
            {!! Form::submit('Like', ['class' => 'btn btn-primary form-control']) !!}
        </div>
    </div>

    {!! Form::close() !!}
    <!--{!! Form::open(['url' => 'article' ]) !!}


    <div class="form-group">
        {!! Form::submit('like', ['class' => 'btn btn-primary form-control']) !!}
    </div>

    {!! Form::close() !!}
    <img href="#popup" data-toggle="modal" class="grid-item1" src="/assets/image/article/thumbnail/{{$article->photo}}">
    -->

@endforeach

0 个答案:

没有答案