public function postComment(PostCommentAlbumRequest $request, $user, $id) { $data = ['comment_status' => 1, 'user_id' => Auth::user()->id, 'album_id' => $id]; if (Comment_album::create(array_merge($data, $request->only('comment_content')))) { return redirect()->route('album.show', [$user, $id])->with(['message' => 'Your comment has been post']); } return redirect()->route('album.show', [$user, $id])->withErrors('Unexpected error!'); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($user, $id) { $album = Album::where(['id' => $id, 'user_id' => $user]); $is_del = true; if (count($album->get()->toArray())) { $images = Album::find($id); if (count($images) > 0) { $images = $images->images()->get()->toArray(); foreach ($images as $image) { $comment_img = Comment_image::where('image_id', $image['id']); if (count($comment_img->get()->toArray())) { if (false == $comment_img->delete()) { $is_del = false; } } if (false == unlink(public_path() . '/' . $image['fullsize_url']) || false == Image::destroy($image['id'])) { $is_del = false; break; } } } $album_id = $album->get()->first()->id; $comment = Comment_album::where('album_id', $album_id); if (count($comment->get()->toArray())) { if (false == $comment->delete()) { $is_del = false; } } if ($album->delete() && true == $is_del) { return redirect()->route('album.index', $user)->with(['message' => 'Album has been delete.']); } } return redirect()->route('album.index', $user)->withErrors('Can not delete album.'); }