/** * Remove the specified resource from storage. * * @param int $id * * @return Response */ public function destroy($id) { $this->checkUserIsLogged(); $restaurant = Restaurant::where('user_id', $this->user->id)->where('id', $id)->first(); if ($restaurant) { Restaurant::destroy($restaurant->id); return response()->json(["msg" => "Success", "data" => true], 200); } else { return response()->json(["msg" => "Error deleting restaurant", "data" => false], 404); } }
function updateRestaurant(Request $request) { $current_user = Session::get('user'); if (isset($current_user)) { $isOwner = Item::where('user_id', $current_user[5])->where('item_id', $request->item_id)->exists(); if ($current_user[4] == "Admin" || $isOwner) { $item = Item::where('item_id', $request->item_id); $restaurant = Restaurant::where('link_item_id', $request->item_id); $location = Location::where('link_item_id', $request->item_id); $photo = new PhotoGallery(); /*---------------------upload_picture-----------------------*/ $file = Input::file('profile_picture'); if ($file != null) { $destinationPath = 'img/'; $filename = md5(microtime() . $file->getClientOriginalName()) . "." . $file->getClientOriginalExtension(); Input::file('profile_picture')->move($destinationPath, $filename); $num_photo = DB::table('photo_gallery')->count(); $photo->photo_id = DB::table('photo_gallery')->skip($num_photo - 1)->first()->photo_id + 1; $photo->link_item_id = $request->item_id; $photo->photo_url = '/' . $destinationPath . $filename; $item->title_picture = $photo->photo_url; $photo->save(); } /*---------------------------------------------------------*/ $item->title = $request->in_new_title; $item->description = $request->in_new_description; $item->tel = $request->in_new_tel; $item->user_id = $current_user[5]; if ($current_user[4] == 'Admin') { $item->isApproved = 1; } else { $item->isApproved = 0; } $restaurant->price_range = $request->in_new_price_range; $restaurant->food_type = $request->in_new_food_type; $restaurant->oc_time = $request->in_new_oc_time; $restaurant->credit_card = $request->in_new_credit_card; $restaurant->child_appropriate = $request->in_new_child_appropriate; $restaurant->reservable = $request->in_new_reservable; $restaurant->parking = $request->in_new_parking; $location->hint = $request->in_new_hint; $location->build = $request->in_new_build; $location->street_address = $request->in_new_street_address; $location->sub_district = $request->in_new_sub_dis; $location->district = $request->in_new_district; $location->province = $request->in_new_province; $location->postal_code = $request->in_new_post_code; $location->lat = $request->in_new_lat; $location->long = $request->in_new_lng; $item->update(['title' => $item->title, 'description' => $item->description, 'tel' => $item->tel, 'isApproved' => $item->isApproved, 'title_picture' => $item->title_picture]); $location->update(['hint' => $location->hint, 'build' => $location->build, 'street_address' => $location->street_address, 'sub_district' => $location->sub_district, 'district' => $location->district, 'province' => $location->province, 'postal_code' => $location->postal_code, 'lat' => $location->lat, 'long' => $location->long]); $restaurant->update(['price_range' => $request->in_new_price_range, 'food_type' => $request->in_new_food_type, 'oc_time' => $request->in_new_oc_time, 'credit_card' => $request->in_new_credit_card, 'child_appropriate' => $request->in_new_child_appropriate, 'reservable' => $request->in_new_reservable, 'parking' => $request->in_new_parking]); return redirect('/page_restaurant/info/' . $request->item_id); } } return 'fail to authorize permission.'; }