diff --git a/app/Http/Controllers/Admin/RestaurantAppController.php b/app/Http/Controllers/Admin/RestaurantAppController.php index aef5181..ab696ce 100644 --- a/app/Http/Controllers/Admin/RestaurantAppController.php +++ b/app/Http/Controllers/Admin/RestaurantAppController.php @@ -19,15 +19,15 @@ use Exception; class RestaurantAppController extends Controller { - - - + + + public function index_restraunt_users(Request $request) { - + try { $activeQuery = $request->query('active'); @@ -53,7 +53,7 @@ class RestaurantAppController extends Controller // public function change_rest_user_status(Request $request) // { - + // try { // DB::beginTransaction(); // $status = IamPrincipal::find($request->rest_user_id); @@ -94,86 +94,66 @@ class RestaurantAppController extends Controller // } public function change_rest_user_status(Request $request) -{ - try { - DB::beginTransaction(); - $status = IamPrincipal::find($request->rest_user_id); - $status->is_active = $request->status; + { + try { + DB::beginTransaction(); + $status = IamPrincipal::find($request->rest_user_id); + $status->is_active = $request->status; - // Generate a random password if status is 1 (approved) - if ($request->status == 1) { - $randomPassword = \Str::random(8); // Adjust the length as per your requirements - $status->password = bcrypt($randomPassword); // Make sure to hash the password - } - - $status->save(); - - if ($request->status == 1) { - // Fetch user data based on user ID - $user = IamPrincipal::find($request->rest_user_id); - - if ($user) { - // Send email only if user exists - $data = [ - 'first_name' => $user->first_name, - 'last_name' => $user->last_name, - 'email' => $user->email_address, - 'password' => $randomPassword, // Pass the random password to the email template - ]; - - Mail::to($user->email_address)->send(new RestUserApproval($data)); + // Generate a random password if status is 1 (approved) + if ($request->status == 1) { + $randomPassword = \Str::random(8); // Adjust the length as per your requirements + $status->password = bcrypt($randomPassword); // Make sure to hash the password } + + $status->save(); + + if ($request->status == 1) { + // Fetch user data based on user ID + $user = IamPrincipal::find($request->rest_user_id); + + if ($user) { + // Send email only if user exists + $data = [ + 'first_name' => $user->first_name, + 'last_name' => $user->last_name, + 'email' => $user->email_address, + 'password' => $randomPassword, // Pass the random password to the email template + ]; + + Mail::to($user->email_address)->send(new RestUserApproval($data)); + } + } + + DB::commit(); + + return jsonResponseWithSuccessMessage(__('success.update_data')); + } catch (Exception $e) { + Log::error("Update Status function Load Failed " . $e->getMessage()); + return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500); } - - DB::commit(); - - return jsonResponseWithSuccessMessage(__('success.update_data')); - } catch (Exception $e) { - Log::error("Update Status function Load Failed " . $e->getMessage()); - return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500); } -} -// public function view_rest($id) -// { - -// try { -// $restaurantView = IamPrincipal::findOrFail($id); -// // dd($restaurantView); -// return view('Admin.pages.manage_users.restaurants_app.view_restaurant_users', compact('restaurantView')); -// } catch (Exception $e) { -// Log::error("Manage Voucher Page Not Load " . $e->getMessage()); -// return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500); -// } -// } -// public function view_rest($id) -// { -// try { -// $restaurantView = IamPrincipal::findOrFail($id); -// return view('Admin.pages.manage_users.restaurants_app.view_restaurant_users', compact('restaurantView')); -// } catch (Exception $e) { -// Log::error("Manage Voucher Page Not Load " . $e->getMessage()); -// return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500); -// } -// } -public function view_rest($id) -{ - try { - $restaurantView = IamPrincipal::with('restaurant')->findOrFail($id); - return view('Admin.pages.manage_users.restaurants_app.view_restaurant_users', compact('restaurantView')); - } catch (Exception $e) { - Log::error("Manage Voucher Page Not Load " . $e->getMessage()); - return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500); + + + public function view_rest($id) + { + try { + $restaurantView = IamPrincipal::with('restaurant')->findOrFail($id); + return view('Admin.pages.manage_users.restaurants_app.view_restaurant_users', compact('restaurantView')); + } catch (Exception $e) { + Log::error("Manage Voucher Page Not Load " . $e->getMessage()); + return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500); + } } -} -public function edit_Restaurant($id) + public function edit_Restaurant($id) { try { @@ -185,29 +165,144 @@ public function edit_Restaurant($id) } } + // public function updateRest(Request $request) + // { + + + // try { + // DB::beginTransaction(); + // $rest_data = IamPrincipal::where('id', $request->rest_id)->first(); + // $rest_data->first_name = $request->input('name'); + // $rest_data->last_name = $request->input('last_name'); + + // $rest_data->phone_number = $request->input('phone'); + // $rest_data->email_address = $request->input('email_id'); + // $rest_data->save(); + // DB::commit(); + + // return jsonResponseWithSuccessMessage(__('success.update_data')); + // } catch (Exception $e) { + // DB::rollBack(); + // Log::error("updateCustomerNewsArticle Services Page Load Failed " . $e->getMessage()); + // return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500); + // } + // } + + // public function updateRest(Request $request) + // { + // try { + // DB::beginTransaction(); + + // $rest_data = IamPrincipal::find($request->input('rest_id')); + // if (!$rest_data) { + // throw new Exception('Restaurant not found.'); + // } + + // $rest_data->first_name = $request->input('restaurant_name'); + // $rest_data->description = $request->input('restaurant_des'); + // $rest_data->phone_number = $request->input('restaurant_phone'); + // $rest_data->email_address = $request->input('restaurant_email'); + // $rest_data->location = $request->input('restaurant_loc'); + // $rest_data->bio = $request->input('restaurant_bio'); + + // if ($request->hasFile('restaurant_image')) { + // $imagePath = $request->file('restaurant_image')->store('images', 'public'); + // $rest_data->image_path = $imagePath; + // } + + // $rest_data->save(); + + // DB::commit(); + // return response()->json(['message' => __('success.update_data')], 200); + // } catch (Exception $e) { + // DB::rollBack(); + // Log::error("Update Restaurant Failed: " . $e->getMessage()); + // return response()->json(['message' => __('auth.something_went_wrong')], 500); + // } + // } + public function updateRest(Request $request) { - - try { DB::beginTransaction(); - $rest_data = IamPrincipal::where('id', $request->rest_id)->first(); - $rest_data->first_name = $request->input('name'); - $rest_data->last_name = $request->input('last_name'); - $rest_data->phone_number = $request->input('phone'); - $rest_data->email_address = $request->input('email_id'); + $rest_data = IamPrincipal::find($request->input('rest_id')); + // dd($request->all()) ; + if (!$rest_data) { + throw new Exception('Restaurant not found.'); + } + + // $rest_data->first_name = $request->input('restaurant_name'); + // $rest_data->description = $request->input('restaurant_des'); + // $rest_data->phone_number = $request->input('restaurant_Id'); + + $rest_data->phone_number = $request->input('restaurant_phone'); + $rest_data->email_address = $request->input('restaurant_email'); + // $rest_data->location = $request->input('restaurant_loc'); + // $rest_data->bio = $request->input('restaurant_bio'); + + // if ($request->hasFile('restaurant_image')) { + // $imagePath = $request->file('restaurant_image')->store('images', 'public'); + // $rest_data->image_path = $imagePath; + // } + $rest_data->save(); - DB::commit(); - return jsonResponseWithSuccessMessage(__('success.update_data')); + DB::commit(); + return response()->json(['status_code' => 200, 'message' => __('success.update_data')], 200); } catch (Exception $e) { DB::rollBack(); - Log::error("updateCustomerNewsArticle Services Page Load Failed " . $e->getMessage()); + Log::error("Update Restaurant Failed: " . $e->getMessage()); + return response()->json(['status_code' => 500, 'message' => __('auth.something_went_wrong')], 500); + } + } + + public function delete_restaurants($id) + { + + try { + DB::beginTransaction(); + + $restaurant = IamPrincipal::find($id); + $restaurant->delete(); + + DB::commit(); + + return response()->json(['success' => true, 'status' => 200]); + } catch (Exception $e) { + DB::rollBack(); + Log::error("delete_passport function Load Failed " . $e->getMessage()); + return response()->json(['success' => false, 'status' => 500, 'message' => __('auth.something_went_wrong')]); + } + } + + + public function archive_restaturant() + { + + try { + $rest_user = IamPrincipal::where('principal_type_xid', 4)->onlyTrashed()->latest()->get(); + return view('Admin.pages.manage_users.restaurants_app.archive_manage_restaurant', compact('rest_user')); + } catch (Exception $e) { + Log::error("Manage Voucher Page Not Load " . $e->getMessage()); return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500); } } + public function unarchive_rest($id) + { + + try { + DB::beginTransaction(); + IamPrincipal::withTrashed()->where('id', $id)->restore(); + + DB::commit(); + + return response()->json(['success' => true, 'status' => 200]); + } catch (Exception $e) { + DB::rollBack(); + Log::error("delete_passport function Load Failed " . $e->getMessage()); + return response()->json(['success' => false, 'status' => 500, 'message' => __('auth.something_went_wrong')]); + } + } + } - - - diff --git a/public/assets/js/admin/manage_restaurant/main.js b/public/assets/js/admin/manage_restaurant/main.js index c68e454..26f9b82 100644 --- a/public/assets/js/admin/manage_restaurant/main.js +++ b/public/assets/js/admin/manage_restaurant/main.js @@ -37,7 +37,7 @@ $(document).on("click", ".restaurants_archive", function (e) { if (response.status == 200) { toastr.success('Record has been archive'); setTimeout(function () { - window.location.href = base_url + "/manage_restraunt"; + window.location.href = base_url + "/restaurant_users"; }, 1000); } else { toastr.error("Something went wrong"); @@ -69,7 +69,7 @@ $(document).on("click", ".restaurant_unarchive", function (e) { if (response.status == 200) { toastr.success('Record has been'); setTimeout(function () { - window.location.href = base_url + "/manage_restraunt"; + window.location.href = base_url + "/restaurant_users"; }, 1000); } else { toastr.error("Something went wrong"); @@ -255,107 +255,112 @@ $(document).on("click", ".restaurant_unarchive", function (e) { }); }); - - $('#restaurant_user_form').validate({ - ignore: [], - debug: false, - rules: { - restaurant_name: { - required: true, - fullNameCharactersOnly: true - }, - restaurant_des:{ - required: true, - }, - restaurant_Id:{ - required: true, - }, - restaurant_loc:{ - required: true, - }, - restaurant_email: { - required: true, - email: true, - }, - restaurant_image: { - required: true, - }, - restaurant_phone: { - required: true, - numericCharactersOnly: true - }, - restaurant_bio:{ - required: true, - }, - }, - messages: { - restaurant_name: { - required: "Enter Passport Name", - alphaCharactersOnly: "Please enter only alphabetical characters" - }, - restaurant_des:{ - required: "Please enter description", - }, - restaurant_Id:{ - required: "Please enter restaurant Id", - }, - restaurant_loc:{ - required: "Please enter location", - }, - restaurant_email: { - required: "Enter email address", - email: "Please enter a valid email address" - }, - restaurant_image: { - required: "Please select the image", - }, - restaurant_phone: { - required: "Enter Phone Number", - numericCharactersOnly: "Please enter only numeric characters" - }, - restaurant_bio:{ - required: "Please enter bio", - }, - }, - errorClass: 'error-message', - submitHandler: function(form) { - let base_url = url_path; - var formData = new FormData(form); - - $('#restaturant_user_btn').text('Please wait...'); - $('#restaturant_user_btn').attr('disabled', true); - - $.ajaxSetup({ - headers: { - 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') + $(document).ready(function() { + // console.log('dfkjb'); + $('#rest_user_form').validate({ + ignore: [], + debug: false, + rules: { + // restaurant_name: { + // required: true, + // fullNameCharactersOnly: true + // }, + // restaurant_des:{ + // required: true, + // }, + // restaurant_Id:{ + // required: true, + // }, + // restaurant_loc:{ + // required: true, + // }, + restaurant_email: { + required: true, + email: true, + }, + // restaurant_image: { + // required: true, + // }, + restaurant_phone: { + required: true, + numericCharactersOnly: true + }, + // restaurant_bio:{ + // required: true, + // }, + }, + messages: { + // restaurant_name: { + // required: "Enter Passport Name", + // alphaCharactersOnly: "Please enter only alphabetical characters" + // }, + // restaurant_des:{ + // required: "Please enter description", + // }, + // restaurant_Id:{ + // required: "Please enter restaurant Id", + // }, + // restaurant_loc:{ + // required: "Please enter location", + // }, + restaurant_email: { + required: "Enter email address", + email: "Please enter a valid email address" + }, + // restaurant_image: { + // required: "Please select the image", + // }, + restaurant_phone: { + required: "Enter Phone Number", + numericCharactersOnly: "Please enter only numeric characters" + }, + // restaurant_bio:{ + // required: "Please enter bio", + // }, + }, + errorClass: 'error-message', + submitHandler: function(form) { + let base_url = url_path; + var formData = new FormData(form); + // console.log(formData); + $('#restaturant_btn').text('Please wait...'); + $('#restaturant_btn').attr('disabled', true); + + $.ajaxSetup({ + headers: { + 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') + } + }); + $.ajax({ + url: base_url + '/update_restaurant', + type: 'POST', + data: formData, + processData: false, + contentType: false, + success: function(result) { + if (result.status_code == 200) { + toastr.success('Restaurant Updated Sucessfully'); + setTimeout(function() { + window.location.href = base_url + "/restaurant_users"; + }, 2000); + } else { + toastr.error('Something Went Wrong'); + setTimeout(function() { + window.location.href = base_url + "/restaurant_users"; + }, 2000); + } + $('#restaturant_btn').attr('disabled', false); + $('#restaturant_btn').text('Submit'); + }, + error: function() { + toastr.error('Something Went Wrong'); + $('#restaturant_btn').attr('disabled', false); + $('#restaturant_btn').text('Submit'); + } + }); } }); - $.ajax({ - url: base_url + '/update_restaurant', - type: 'POST', - data: formData, - processData: false, - contentType: false, - success: function(result) { - - if (result.status_code == 200) { - toastr.success('Restaurant Updated Sucessfully'); - setTimeout(function() { - window.location.href = base_url + "/restaurant_users"; - }, 2000); - } else { - toastr.error('Something Went Wrong'); - setTimeout(function() { - window.location.href = base_url + "/restaurant_users"; - }, 2000); - } - $('#restaturant_user_btn').attr('disabled', false); - $('#restaturant_user_btn').text('Submit'); - }, - - }); - - $('#restaturant_user_btn').attr('disabled', false); - $('#restaturant_user_btn').text('Submit'); - } - }); \ No newline at end of file + }) + + + \ No newline at end of file diff --git a/resources/views/Admin/pages/manage_users/restaurants_app/archive_manage_restaurant.blade.php b/resources/views/Admin/pages/manage_users/restaurants_app/archive_manage_restaurant.blade.php new file mode 100644 index 0000000..0bf55ca --- /dev/null +++ b/resources/views/Admin/pages/manage_users/restaurants_app/archive_manage_restaurant.blade.php @@ -0,0 +1,114 @@ +@extends('Admin.layouts.master') + +@section('content') +@php +$currentPage = 'manage-restaurant_app'; +@endphp + + + + +
+
+
+ +
+
+ + + + + + + + + + + + + + + @foreach ($rest_user as $rest_users) + + + + + + + + + + + + + @endforeach + + + +
Sr noResturant NameResturant IDEmail IdDate OnboardedPhone NumberLocationAction
{{$rest_users->first_name}}{{$rest_users->id}}{{$rest_users->email_address}}{{ \Carbon\Carbon::parse($rest_users->created_at)->format('d-m-y') }}{{$rest_users->phone_number }}{{ $rest_users->state->name}} + + + Restore + +
+
+
+
+
+
+ + + @endsection + @section('section_script') + + + +@endsection diff --git a/resources/views/Admin/pages/manage_users/restaurants_app/edit_restaurant_users.blade.php b/resources/views/Admin/pages/manage_users/restaurants_app/edit_restaurant_users.blade.php index 8730824..c938547 100644 --- a/resources/views/Admin/pages/manage_users/restaurants_app/edit_restaurant_users.blade.php +++ b/resources/views/Admin/pages/manage_users/restaurants_app/edit_restaurant_users.blade.php @@ -36,22 +36,22 @@ $currentPage = 'manage-restaurant_app';
-
+
-
+ +
@@ -76,20 +76,20 @@ $currentPage = 'manage-restaurant_app';
-
+ -
+ +
-
+ +
@@ -117,8 +119,7 @@ $currentPage = 'manage-restaurant_app'; @endsection @section('section_script') - - + + @endsection \ No newline at end of file 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 3b8f631..9e03006 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 @@ -214,7 +214,7 @@ $currentPage = 'manage-restaurant_app'; Edit - + Archive @@ -351,7 +351,7 @@ $currentPage = 'manage-restaurant_app'; @endsection \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index 3a57799..715719e 100644 --- a/routes/web.php +++ b/routes/web.php @@ -64,6 +64,9 @@ Route::get('/change_rest_status', [RestaurantAppController::class, 'change_rest_ Route::get('/view_restaurant_users/{id}', [RestaurantAppController::class, 'view_rest'])->name('restaurantViewUsers'); Route::get('/edit_restaurant_users/{id}', [RestaurantAppController::class, 'edit_Restaurant'])->name('EditRestUsers'); Route::post('/update_restaurant', [RestaurantAppController::class, 'updateRest']); +Route::delete('/manage_restaurants_archive/{id}', [RestaurantAppController::class, 'delete_restaurants']); +Route::get('/manage_restaurants_archive', [RestaurantAppController::class, 'archive_restaturant'])->name('archieve.rest'); +Route::post('/manage_restaurants_unarchive/{id}', [RestaurantAppController::class, 'unarchive_rest']); //*******************************************************manage subadmin********************************************************