Files
cheerstothe_season_2.0/app/Http/Controllers/Admin/ManageRestrauntController.php
2024-05-29 17:11:02 +05:30

137 lines
5.1 KiB
PHP

<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Models\ManageRestaurant;
use App\Models\OperatingHour;
use Illuminate\Http\Request;
use Exception;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\DB;
class ManageRestrauntController extends Controller
{
public function index()
{
$restaurant = ManageRestaurant::with('operatingHours')->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 {
$hours = OperatingHour::where('manage_restaurant_xid', $id)->get();
$restaurantItem = ManageRestaurant::where('id', $id)->first();
$restaurantItem['image'] = ListingImageUrl('restaurant_images', $restaurantItem['image']);
// dd($voucherItem);
return view(
'Admin.pages.manage_restaurants.edit_restaurant',
compact(
'restaurantItem',
'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 {
// dd($request);
// DB::beginTransaction();
// $restaurant = ManageRestaurant::where('id', $request->restaurant_id)->first();
// // dd($passport_data);
// if (isset($request->image)) {
// $image = $request->image;
// $image_db = null;
// } else {
// $image = null;
// $image_db = $restaurant->image;
// }
// $normalImage = saveSingleImageWithoutCrop($image, 'restaurant_images', $image_db);
// $restaurant->restaurant_name = $request->input('name');
// $restaurant->description = $request->input('description');
// $restaurant->image = $normalImage;
// $restaurant->restaurant_id = $request->input('rest_id');
// $restaurant->city_xid = $request->input('city');
// $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();
// 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);
// }
// }
}