public function deleteLightboxImage($id) { if (Request::ajax()) { $arrReturn = ['status' => 'error', 'message' => 'Please refresh and try again.']; $lightboxImages = LightboxImages::findorFail($id); $lightbox_id = $lightboxImages->lightbox_id; if ($lightboxImages->delete()) { $query = LightboxImages::where('lightbox_id', '=', $lightbox_id); $data = $query->get(); if ($data->count() <= 0) { $lightbox = Lightbox::findorFail($lightbox_id); $lightbox->delete(); $html = $this->showLightboxs(true); $arrReturn = ['status' => 'ok', 'message' => "Your lightbox's image has been deleted.", 'html' => $html]; } else { return $this->lightboxDetail($lightbox_id); } } $response = Response::json($arrReturn); $response->header('Content-Type', 'application/json'); return $response; } return App::abort(404); }