public function postComment(PostCommentImageRequest $request, $user, $id)
 {
     $image = Image::where(['id' => $id, 'user_id' => $user]);
     if (count($image->get()) == 0) {
         if ($request->ajax()) {
             return json_encode(['error' => 1, 'message' => 'Opps! Cann\'t post your comment! Maybe photo has been delete!']);
         }
         return redirect()->route('photo.show', [$user, $id])->withErrors('The photo does not exist!');
     }
     $data = ['comment_status' => 1, 'user_id' => \Auth::user()->id, 'image_id' => $id];
     if (Comment_image::create(array_merge($request->except('_token'), $data))) {
         if ($request->ajax()) {
             return json_encode(['error' => 0, 'message' => $request->get('comment_content'), 'commentCount' => $image->first()->comments()->count(), 'author' => \Auth::user()->name, 'route' => route('user.profile', Auth::user()->id)]);
         }
         return redirect()->route('photo.show', [$user, $id])->with(['message' => 'Your comment has been post']);
     }
     if ($request->ajax()) {
         return json_encode(['error' => 1, 'message' => 'Opps! Cann\'t post your comment! Maybe photo has been delete!']);
     }
     return redirect()->route('photo.show', [$user, $id])->withErrors('Unexpected errors');
 }
Пример #2
0
 /**
  * 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.');
 }
Пример #3
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($user, $id)
 {
     $image = Image::where(['id' => $id, 'user_id' => $user]);
     if (count($image->get()->toArray()) > 0) {
         if (count(Comment_image::find($id)) > 0) {
             Comment_image::where('image_id', $id)->delete();
         }
         if (unlink(public_path() . '/' . $image->get()->first()->fullsize_url) && $image->delete()) {
             return redirect()->route('photo.index', $user)->with(['message' => 'The image has been delete.']);
         }
     }
     return redirect()->route('photo.index', $user)->withErrors('The image does not exists.');
 }