英文:
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->products
in the blade directly
@foreach($lesson->products as $product)
<img src="{{ asset('storage/'.$product->image) }}" alt="">
@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)
<img src="{{ asset('storage/'.$product->image) }}" alt="">
@endforeach
@endforeach
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论