diff --git a/app/Http/Controllers/Admin/RestaurantAppController.php b/app/Http/Controllers/Admin/RestaurantAppController.php index a0131c6..2563a8c 100644 --- a/app/Http/Controllers/Admin/RestaurantAppController.php +++ b/app/Http/Controllers/Admin/RestaurantAppController.php @@ -56,7 +56,7 @@ class RestaurantAppController extends Controller $restaurantIds = $user->getresturant->pluck('restaurant_xid')->toArray(); $user->restaurants = ManageRestaurant::whereIn('id', $restaurantIds) - ->select('id', 'name', 'image', 'address', 'latitude', 'longtitude') + ->select('id','restaurant_id', 'name', 'image', 'address', 'latitude', 'longtitude') ->get(); // Optionally, if you want to format the images as in the previous example @@ -172,37 +172,20 @@ class RestaurantAppController extends Controller * Created at : 03 June 2024 * Use : To view restaturant user. */ - + public function view_rest($id) { try { - $restaurantView = IamPrincipal::with('restaurant')->findOrFail($id); - - // Check if restaurant_users is not null before iterating over it - if (!is_null($restaurantView->restaurant_users)) { - foreach ($restaurantView->restaurant_users as $user) { - $restaurantIds = $user->getresturant->pluck('restaurant_xid')->toArray(); - - $userRestaurants = ManageRestaurant::whereIn('id', $restaurantIds) - ->select('id', 'name', 'image', 'address', 'latitude', 'longtitude') - ->get(); - - foreach ($userRestaurants as $restaurant) { - $restaurant->image = ListingImageUrl('restaurant_images', $restaurant->image); - } - - $user->restaurants = $userRestaurants; - } - } - // return $restaurantView; - - return view('Admin.pages.manage_users.restaurants_app.view_restaurant_users', compact('restaurantView')); + $restdata = IamPrincipalRestaurantRole::with('restaurant','customer')->where('principal_xid', $id)->first(); + // return $restdata; + + return view('Admin.pages.manage_users.restaurants_app.view_restaurant_users', compact('restdata')); } catch (Exception $e) { Log::error("Manage Voucher Page Not Load " . $e->getMessage()); return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500); } } - + /** @@ -295,13 +278,13 @@ class RestaurantAppController extends Controller throw new Exception('Restaurant not found.'); } - + $rest_data->first_name = $request->input('first_name'); $rest_data->last_name = $request->input('last_name'); $rest_data->phone_number = $request->input('restaurant_phone'); $rest_data->date_of_birth = $request->input('user_birth'); - + $rest_data->save(); diff --git a/app/Models/IamPrincipalRestaurantRole.php b/app/Models/IamPrincipalRestaurantRole.php index 5fcc673..295b360 100644 --- a/app/Models/IamPrincipalRestaurantRole.php +++ b/app/Models/IamPrincipalRestaurantRole.php @@ -17,7 +17,13 @@ class IamPrincipalRestaurantRole extends Model 'created_by', 'modified_by', ]; - - - + + public function restaurant() + { + return $this->belongsTo(ManageRestaurant::class, 'restaurant_xid', 'id'); + } + public function customer() + { + return $this->belongsTo(IamPrincipal::class, 'principal_xid', 'id'); + } } diff --git a/resources/views/Admin/pages/manage_users/restaurants_app/restaurants_users.blade.php b/resources/views/Admin/pages/manage_users/restaurants_app/restaurants_users.blade.php index 391ed7f..5395b6d 100644 --- a/resources/views/Admin/pages/manage_users/restaurants_app/restaurants_users.blade.php +++ b/resources/views/Admin/pages/manage_users/restaurants_app/restaurants_users.blade.php @@ -114,7 +114,7 @@ $currentPage = 'manage-restaurant_app'; {{ $restaurant->name }} @endforeach - {{ $restaurant->id }} + {{ $restaurant->restaurant_id }} {{ $restaurant_user->email_address }} {{ $restaurant_user->created_at->format('d/m/Y') }} {{ $restaurant_user->state ? $restaurant_user->state->name : 'No state assigned' }} diff --git a/resources/views/Admin/pages/manage_users/restaurants_app/view_restaurant_users.blade.php b/resources/views/Admin/pages/manage_users/restaurants_app/view_restaurant_users.blade.php index afcf33a..fef01ec 100644 --- a/resources/views/Admin/pages/manage_users/restaurants_app/view_restaurant_users.blade.php +++ b/resources/views/Admin/pages/manage_users/restaurants_app/view_restaurant_users.blade.php @@ -41,20 +41,14 @@ $currentPage = 'manage-restaurant_app'; - - - - {{ !empty($restaurantView->restaurant) ? $restaurantView->restaurant[0]->name : 'NA' }} + {{ $restdata->restaurant->name ?? 'NA' }} + {{ $restdata->restaurant->restaurant_id ?? 'NA' }} + {{ $restdata->customer->email_address ?? 'NA' }} + {{ $restdata->customer->created_at ?? 'NA' }} - {{ !empty($restaurantView->restaurant) ? $restaurantView->restaurant[0]->restaurant_id : 'NA' }} - {{ $restaurantView->email_address }} - - {{ $restaurantView->created_at->format('d/m/Y') }} - - - + @@ -71,9 +65,8 @@ $currentPage = 'manage-restaurant_app'; While at Restaurant be sure to try : --> - {{ $restaurantView->state->name}} - - {{ $restaurantView->phone_number}} + {{ $restdata->customer->state_xid}} + {{ $restdata->customer->phone_number}}