删除回复
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'];
|
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));
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -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)
|
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>
|
<span class="meta" title="{{ $reply->created_at }}">{{ $reply->created_at->diffForHumans() }}</span>
|
||||||
|
|
||||||
{{-- 回复删除按钮 --}}
|
{{-- 回复删除按钮 --}}
|
||||||
|
@can('destroy',$reply)
|
||||||
<span class="meta pull-right">
|
<span class="meta pull-right">
|
||||||
<a title="删除回复">
|
<form action="{{route('replies.destroy',$reply->id)}}" method="post">
|
||||||
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span>
|
{{csrf_field()}}
|
||||||
</a>
|
{{method_field('DELETE')}}
|
||||||
|
<button type="submit" class="btn btn-default btn-xs pull-left">
|
||||||
|
<i class="glyphicon glyphicon-trash"></i>
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
</span>
|
</span>
|
||||||
|
@endcan
|
||||||
</div>
|
</div>
|
||||||
<div class="reply-content">
|
<div class="reply-content">
|
||||||
{!! $reply->content !!}
|
{!! $reply->content !!}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user