_reply_list 中使用分页通知如何定位到回复的位置
在6.1节中,topic.show显示reply_list并没有使用分页
resources/views/topics/index.blade.php
.
.
.
<div class="panel panel-default topic-reply">
<div class="panel-body">
@includeWhen(Auth::check(),'topics._reply_box',['topic' => $topic])
@include('topics._reply_list',['replies' => $topic->replies()->with('user')->get()])
</div>
</div>
.
.
.
我把这个列表显示加上了分页
.
.
.
<div class="panel panel-default topic-reply">
<div class="panel-body">
@includeWhen(Auth::check(),'topics._reply_box',['topic' => $topic])
@include('topics._reply_list',['replies' => $topic->replies()->with('user')->paginate(5)])
</div>
</div>
.
.
.
resources/views/topics/_reply_list.blade.php
<div class="reply_list">
@foreach($replies as $reply)
<div class="media" name="reply{{ $reply->id }}" id="reply{{ $reply->id }}">
<div class="avatar pull-left">
<a href="{{ route('users.show', [$reply->user_id]) }}">
<img class="media-object img-thumbnail" alt="{{ $reply->user->name }}"
src="{{ $reply->user->avatar }}"
style="width:48px;height:48px;"/>
</a>
</div>
<div class="infos">
<div class="media-heading">
<a href="{{ route('users.show', [$reply->user_id]) }}" title="{{ $reply->user->name }}">
{{ $reply->user->name }}
</a>
<span> • </span>
<span class="meta" title="{{ $reply->created_at }}">{{ $reply->created_at->diffForHumans() }}</span>
@can('destroy',$reply)
<span class="meta pull-right">
<form action="{{ route('replies.destroy',$reply->id) }}" method="post">
{{ csrf_field() }}
{{ method_field('DELETE') }}
<button type="submit" class="btn btn-default btn-xs pull-left">
<i class="glyphicon glyphicon-trash"></i>
</button>
</form>
</span>
@endcan
</div>
<div class="reply-content">
{!! $reply->content !!}
</div>
</div>
</div>
<hr>
@endforeach
{!! $replies->render() !!}
</div>
分页很简单的就实现了,但是在通知内容中的这个$url
app/Notifications/TopicReplied.php
.
.
.
public function toMail($notifiable)
{
$url = $this->reply->topic->link(['#reply' . $this->reply->id]);
return (new MailMessage)
->line('您的话题有新回复!')
->action('查看回复', $url);
}
.
.
.
这里的#reply . $this->reply->id
是用来在页面中定位评论内容的位置的,如果使用分页的话,如果通知的评论已经不在第一页了,那不是就定位不到了吗?我想问下大家是怎么解决这个问题的。
推荐文章: