删除回复

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']; 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)); 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)); $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) 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> <span class="meta" title="{{ $reply->created_at }}">{{ $reply->created_at->diffForHumans() }}</span>
{{-- 回复删除按钮 --}} {{-- 回复删除按钮 --}}
<span class="meta pull-right"> @can('destroy',$reply)
<a title="删除回复"> <span class="meta pull-right">
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span> <form action="{{route('replies.destroy',$reply->id)}}" method="post">
</a> {{csrf_field()}}
</span> {{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>
<div class="reply-content"> <div class="reply-content">
{!! $reply->content !!} {!! $reply->content !!}