我正在建立一个票务系统。票证可以有多个评论。但是我怎么能对此进行分页呢?
这是我的控制者:
public function showTicket($slug)
{
$ticket = Ticket::whereSlug($slug);
if(Auth::user()->id == $ticket->user_id)
{
return view('users.ticket')->with('ticket',$ticket);
}
}
这是我现在的观点:
@foreach($ticket->reactions as $reaction)
<div class="panel panel-default">
<div class="panel-heading"><strong>{!! ucfirst($reaction->user->name) !!} {!! $reaction->user->lastname !!}<span class="pull-right">{!! $reaction->created_at !!}</span></strong></div>
<div class="panel-body">
{!! $reaction->content !!}
</div>
</div>
@endforeach
当我在控制器中说:
$ticket = Ticket::whereSlug($slug)->paginate(15);
在我看来:
{!! $ticket->reactions->render() !!}
它不起作用。
答案 0 :(得分:0)
在您的控制器中
function showTicket($slug)
{
$ticket = Thicket::whereSlug($slug)->first();
$reactions = $thicket->reactions()->paginate(15);
if(Auth::user()->id == $ticket->user_id)
return view('users.ticket', compact('ticket', 'reactions'));
}
并在您的视图中
@foreach($reactions as $reaction)
<div class="panel panel-default">
<div class="panel-heading"><strong>{!! ucfirst($reaction->user->name) !!} {!! $reaction->user->lastname !!}<span class="pull-right">{!! $reaction->created_at !!}</span></strong></div>
<div class="panel-body">
{!! $reaction->content !!}
</div>
</div>
@endforeach