Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel 5.6如何在一篇文章中显示少量图片_Laravel_Object_Laravel Blade - Fatal编程技术网

Laravel 5.6如何在一篇文章中显示少量图片

Laravel 5.6如何在一篇文章中显示少量图片,laravel,object,laravel-blade,Laravel,Object,Laravel Blade,下午好 我在博客上工作,我有文章的细节,想展示一些图片 我现在得到的是: 正如你所看到的,我正在获取内容和内容后的图片。这也是刀片的代码 <div class="container"> @foreach($articles as $article) <article> <h1 class="title is-1"><a href="{{route('show', $article->id)}}"&g

下午好

我在博客上工作,我有文章的细节,想展示一些图片

我现在得到的是:

正如你所看到的,我正在获取内容和内容后的图片。这也是刀片的代码

<div class="container">
      @foreach($articles as $article)
        <article>
          <h1 class="title is-1"><a href="{{route('show', $article->id)}}">{{$article->title}}</a></h1>
            @foreach($article->images as $image)
              <figure class="image is-128x128">
                <img src="{{$image->path}}" alt="{{$image->title}}">
              </figure>
            @endforeach
          <p>{{$article->content}}</p>
        </article>
      @endforeach
    </div>

@foreach($articles作为$article)
@foreach($article->image as$image)
路径}“alt=“{{$image->title}}”>
@endforeach
{{$article->content}

@endforeach
因为我得到了一个对象,所以我无法分割图片

  • 确保
    $image->path
    是图像文件的正确路径(如果是url,请跳过这一点)。 您可以通过回显或直接dd($image->path)进行检查

  • 要访问图像,它需要位于laravel的公用文件夹中

  • 如果您希望将文件保存在存储文件夹中并公开访问,则需要创建一个符号链接


    很难弄明白你想要什么,但我很肯定我终于明白了

    你想做的事情是这样的:

    <div class="container">
      @foreach($articles as $article)
        <article>
          <h1 class="title is-1"><a href="{{route('show', $article->id)}}">{{$article->title}}</a></h1>
          @if(count($article->images) > 0)
            <figure class="image is-128x128">
              <img src="{{$article->images->first()->path}}" alt="{{$article->images->first()->title}}">
            </figure>
          @endif
          <p>{{$article->content}}</p>
          @if(count($article->images) > 1)
            @foreach($article->images->slice(1) as $image)
              <figure class="image is-128x128">
                <img src="{{$image->path}}" alt="{{$image->title}}">
              </figure>
            @endforeach
          @endif
        </article>
      @endforeach
    </div>
    
    
    @foreach($articles作为$article)
    @如果(计数($article->images)>0)
    images->first()->path}“alt=“{{{$article->images->first()->title}>
    @恩迪夫
    {{$article->content}

    @如果(计数($article->images)>1) @foreach($article->images->slice(1)作为$image) 路径}“alt=“{{$image->title}}”> @endforeach @恩迪夫 @endforeach

    这不仅会为您提供标题>图像1>内容>剩余图像,还会确保您仅在实际有可用图像时打印图像。第二个
    @if()内的
    $article->images->slice(1)
    将确保我们不会再次使用第一个图像。

    哦,我明白了。你认为我不应该使用mysql保存路径吗?你的问题到底是什么?非常简单。正如你在图片上看到的那样。我需要文本、图片、文本。现在我只有文本和图片。非常感谢这个解决方案正在工作。我需要阅读文档离子!