/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy(Request $request, $id) { if (!$request->has('reason')) { return 'invalid_request'; } $reason = trim($request->get('reason')); if ($reason == '') { return 'invalid_request'; } $user = auth()->check() ? auth()->user() : null; if (is_null($user)) { return 'not_logged_in'; } if (!$user->can('delete_comment')) { return 'insufficient_permissions'; } $comment = Comment::whereId($id)->first(); if (is_null($comment)) { return 'comment_not_found'; } $receiver = $comment->user; $video = $comment->video; Comment::destroy($id); if ($user->id != $receiver->id) { Message::send(1, $receiver->id, 'A moderator deleted your comment', view('messages.moderation.commentdelete', ['video' => $video, 'comment' => $comment, 'reason' => $reason])); } $log = new ModeratorLog(); $log->user()->associate($user); $log->type = 'delete'; $log->target_type = 'comment'; $log->target_id = $id; $log->reason = $reason; $log->save(); return 'success'; }