删除回复

This commit is contained in:
fthvgb1 2018-01-31 23:00:57 +08:00
parent 3a24232413
commit dc18c87fca
5 changed files with 23 additions and 7 deletions

View File

@ -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));
}

View File

@ -28,4 +28,9 @@ class ReplyObserver
$topic->user->notify(new TopicReplied($reply));
}
}
public function deleted(Reply $reply)
{
$reply->topic->decrement('reply_count', 1);
}
}

View File

@ -33,4 +33,9 @@ class TopicObserver
{
//
}
public function deleted(Topic $topic)
{
\DB::table('replies')->where('topic_id', $topic->id)->delete();
}
}

View File

@ -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);
}
}

View File

@ -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 !!}