latest()->get(); return view('Admin.pages.manage_restaurants.manage_restaurants', compact('restaurant')); } public function add() { return view('Admin.pages.manage_restaurants.add_restaurant'); } public function store_restaurant(Request $request) { try { DB::beginTransaction(); // Handling image upload if ($request->hasFile('image')) { $image = $request->file('image'); $imagePath = saveSingleImageWithoutCrop($image, 'restaurant_images'); } else { $imagePath = $request->image; } // Creating the restaurant $restaurant = new ManageRestaurant(); $restaurant->name = $request->input('name'); $restaurant->description = $request->input('description'); $restaurant->image = $imagePath; $restaurant->restaurant_id = $request->input('rest_id'); $restaurant->address = $request->input('address'); $restaurant->bio = $request->input('bio'); $restaurant->latitude = $request->input('latitude'); $restaurant->longtitude = $request->input('longitude'); $restaurant->exclusion = $request->input('exclusion'); $restaurant->try_on_1 = $request->input('try_on_1'); $restaurant->try_on_2 = $request->input('try_on_2'); $restaurant->try_on_3 = $request->input('try_on_3'); $restaurant->try_on_4 = $request->input('try_on_4'); $restaurant->save(); foreach ($request->input('operating_hours') as $day => $hours) { OperatingHour::create([ 'manage_restaurant_xid' => $restaurant->id, 'day_of_week' => $day, 'start_time' => $hours['start_time'], 'end_time' => $hours['end_time'] ]); } DB::commit(); return jsonResponseWithSuccessMessage(__('success.save_data')); } catch (Exception $e) { DB::rollBack(); Log::error("Restaurant Store Page Load Failed: " . $e->getMessage()); return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500); } } public function edit_restaurant(Request $request, $id) { try { $operating_hours = OperatingHour::where('manage_restaurant_xid', $id)->get()->keyBy('day_of_week'); $restaurantItem = ManageRestaurant::where('id', $id)->first(); $restaurantItem['image'] = ListingImageUrl('restaurant_images', $restaurantItem['image']); return view( 'Admin.pages.manage_restaurants.edit_restaurant', compact( 'restaurantItem', 'operating_hours' ) ); } catch (Exception $e) { Log::error("edit voucher Page Load Failed " . $e->getMessage()); return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500); } } public function update(Request $request) { try { DB::beginTransaction(); $restaurant = ManageRestaurant::where('id', $request->id)->first(); if ($request->hasFile('image')) { $image = $request->file('image'); $imagePath = saveSingleImageWithoutCrop($image, 'restaurant_images'); } else { $imagePath = $restaurant->image; } $restaurant->name = $request->input('name'); $restaurant->description = $request->input('description'); $restaurant->image = $imagePath; $restaurant->restaurant_id = $request->input('restaurant_id'); $restaurant->address = $request->input('location_name'); $restaurant->exclusion = $request->input('exclusion'); $restaurant->latitude = $request->input('latitude'); $restaurant->longtitude = $request->input('longitude'); $restaurant->bio = $request->input('bio'); $restaurant->try_on_1 = $request->input('try_on_1'); $restaurant->try_on_2 = $request->input('try_on_2'); $restaurant->try_on_3 = $request->input('try_on_3'); $restaurant->try_on_4 = $request->input('try_on_4'); $restaurant->save(); OperatingHour::where('manage_restaurant_xid', $restaurant->id)->delete(); foreach ($request->input('operating_hours') as $day => $hours) { OperatingHour::create([ 'manage_restaurant_xid' => $restaurant->id, 'day_of_week' => $day, 'start_time' => $hours['start_time'], 'end_time' => $hours['end_time'] ]); } DB::commit(); return jsonResponseWithSuccessMessage(__('success.update_data')); } catch (Exception $e) { DB::rollBack(); Log::error("update Restaurant Services Page Load Failed " . $e->getMessage()); return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500); } } public function viewRestaurant(Request $request, $id) { try { $restaurantItem = ManageRestaurant::where('id', $id)->first(); $restaurantItem['image'] = ListingImageUrl('restaurant_images', $restaurantItem['image']); $operating_hours = OperatingHour::where('manage_restaurant_xid', $id)->get()->keyBy('day_of_week'); return view('Admin.pages.manage_restaurants.view_restaurant', compact('restaurantItem','operating_hours')); } catch (Exception $e) { Log::error("view Voucher Load Failed " . $e->getMessage()); return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500); } } }