Skip to content

Commit

Permalink
Episode 33
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffreyWay committed May 1, 2017
1 parent 63c5ff7 commit 0d70375
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
4 changes: 4 additions & 0 deletions app/Http/Controllers/RepliesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ public function destroy(Reply $reply)

$reply->delete();

if (request()->expectsJson()) {
return response(['status' => 'Reply deleted']);
}

return back();
}
}
7 changes: 7 additions & 0 deletions public/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -1960,6 +1960,13 @@ Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
this.editing = false;

flash('Updated!');
},
destroy: function destroy() {
axios.delete('/replies/' + this.attributes.id);

$(this.$el).fadeOut(300, function () {
flash('Your reply has been deleted.');
});
}
}
});
Expand Down
8 changes: 8 additions & 0 deletions resources/assets/js/components/Reply.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@
this.editing = false;
flash('Updated!');
},
destroy() {
axios.delete('/replies/' + this.attributes.id);
$(this.$el).fadeOut(300, () => {
flash('Your reply has been deleted.');
});
}
}
}
Expand Down
8 changes: 1 addition & 7 deletions resources/views/threads/reply.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,7 @@
@can ('update', $reply)
<div class="panel-footer level">
<button class="btn btn-xs mr-1" @click="editing = true">Edit</button>

<form method="POST" action="/replies/{{ $reply->id }}">
{{ csrf_field() }}
{{ method_field('DELETE') }}

<button type="submit" class="btn btn-danger btn-xs">Delete</button>
</form>
<button class="btn btn-xs btn-danger mr-1" @click="destroy">Delete</button>
</div>
@endcan
</div>
Expand Down

0 comments on commit 0d70375

Please sign in to comment.