未定义的属性:Illuminate\Pagination\Paginator::$image

huangapple go评论53阅读模式
英文:

Undefined property: Illuminate\Pagination\Paginator::$image

问题

我需要你帮忙解决这个 `simplePaginate();` 控制器中的问题:

    foreach($lesson->products as $product)
    {
        $p[] = $product->simplePaginate(1);
    }

视图部分:

    @foreach($p as $data)
        <img src="{{ asset('storage/'.$data->image) }}" alt="">
    @endforeach

{{ $p->links('layouts.paginate') }} 

为什么会出现这个错误:

Undefined property: Illuminate\Pagination\Paginator::$image

英文:

I need your help with this simplePaginate();
controller:

foreach($lesson->products as $product)
{
    $p[] = $product->simplePaginate(1);
}

view:

            @foreach($p as $data)
                <img src="{{ asset('storage/'.$data->image) }}" alt="">
            @endforeach

        {{ $p->links('layouts.paginate') }}

what is wrong that I got this error:

Undefined property: Illuminate\Pagination\Paginator::$image

答案1

得分: 2

为什么不直接在Blade模板中移除foreach循环,直接在Blade模板中生成$p并循环$lesson->products

@foreach($lesson->products as $product)
    <img src="{{ asset('storage/'.$product->image) }}" alt="">
@endforeach

如果你需要使用simplePaginate() 而没有在你的问题中提到的原因,那么你可以像这样循环它:

@foreach($p as $productSimplePaginate)
    @foreach($productSimplePaginate as $product)
        <img src="{{ asset('storage/'.$product->image) }}" alt="">
    @endforeach
@endforeach
英文:

Why dont you remove that foreach to generate $p and loop $lesson-&gt;products in the blade directly

@foreach($lesson-&gt;products as $product)
    &lt;img src=&quot;{{ asset(&#39;storage/&#39;.$product-&gt;image) }}&quot; alt=&quot;&quot;&gt;
@endforeach

If you need the simplePaginate() for reasons not posted in your question, then you can loop it like this

@foreach($p as $productSimplePaginate)
    @foreach($productSimplePaginate as $product)
        &lt;img src=&quot;{{ asset(&#39;storage/&#39;.$product-&gt;image) }}&quot; alt=&quot;&quot;&gt;
    @endforeach
@endforeach

huangapple
  • 本文由 发表于 2023年2月10日 05:08:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/75404433.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定