我想有分页在单一的帖子页,数据来自“内容”表。但我想要有分页时,抓住特定的词(节)作为标题转到下一页在同一篇文章。这有可能用Laravel 5.4来实现吗?
示例:
第1节(这是标题)
文本文本
(下一页>,我想添加下一页,它将转到第2节)
第2节
文本(下一页>)
我的Post.php
public function contents()
{
return $this->hasMany(Content::class);
}刀片视图:
@if($post->contents)
@foreach ($post->contents as $content)
@if ($content->type == "header")
<h4>{{ $content->body }}</h4>
@endif
@if ($content->type == "text")
<p>{{ $content->body }}</p>
@endif
@endforeach
@endif发布于 2019-12-02 11:06:56
对于分页,请在模型中使用paginate()。
public function contents()
{
return $this->hasMany(Content::class)->paginate(1);
}视图文件
@if($post->contents)
@foreach ($post->contents() as $content)
@if ($content->type == "header")
<h4>{{ $content->body }}</h4>
@endif
@if ($content->type == "text")
<p>{{ $content->body }}</p>
@endif
@endforeach
{{ $post->contents()->links() }}
@endifhttps://stackoverflow.com/questions/59136982
复制相似问题