删除回复
This commit is contained in:
parent
3a24232413
commit
dc18c87fca
|
@ -7,7 +7,7 @@ class Topic extends Model
|
|||
protected $fillable = ['title', 'category_id', 'body', 'excerpt', 'slug'];
|
||||
|
||||
|
||||
public function link($params)
|
||||
public function link($params = [])
|
||||
{
|
||||
return route('topics.show', array_merge([$this->id, $this->slug], $params));
|
||||
}
|
||||
|
|
|
@ -28,4 +28,9 @@ class ReplyObserver
|
|||
$topic->user->notify(new TopicReplied($reply));
|
||||
}
|
||||
}
|
||||
|
||||
public function deleted(Reply $reply)
|
||||
{
|
||||
$reply->topic->decrement('reply_count', 1);
|
||||
}
|
||||
}
|
|
@ -33,4 +33,9 @@ class TopicObserver
|
|||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function deleted(Topic $topic)
|
||||
{
|
||||
\DB::table('replies')->where('topic_id', $topic->id)->delete();
|
||||
}
|
||||
}
|
|
@ -15,6 +15,6 @@ class ReplyPolicy extends Policy
|
|||
|
||||
public function destroy(User $user, Reply $reply)
|
||||
{
|
||||
return true;
|
||||
return $user->isAuthorOf($reply) || $user->isAuthorOf($reply->topic);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,11 +17,17 @@
|
|||
<span class="meta" title="{{ $reply->created_at }}">{{ $reply->created_at->diffForHumans() }}</span>
|
||||
|
||||
{{-- 回复删除按钮 --}}
|
||||
@can('destroy',$reply)
|
||||
<span class="meta pull-right">
|
||||
<a title="删除回复">
|
||||
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span>
|
||||
</a>
|
||||
<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 !!}
|
||||
|
|
Loading…
Reference in New Issue
Block a user