2024-05-29 17:11:02 +05:30
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
|
use Illuminate\Http\Request;
|
2024-05-30 19:41:43 +05:30
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
use App\Models\IamPrincipal;
|
|
|
|
|
use App\Models\ManageRestaurant;
|
|
|
|
|
use App\Mail\RestUserApproval;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Support\Facades\Mail;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use Exception;
|
|
|
|
|
|
2024-05-29 17:11:02 +05:30
|
|
|
|
|
|
|
|
class RestaurantAppController extends Controller
|
|
|
|
|
{
|
2024-05-30 19:41:43 +05:30
|
|
|
// public function index()
|
|
|
|
|
// {
|
|
|
|
|
// return view('Admin.pages.manage_users.restaurants_app.restaurants_users');
|
|
|
|
|
// }
|
|
|
|
|
// public function index()
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// try {
|
|
|
|
|
// $restaurant = ManageRestaurant::with('state')->latest()->get();
|
|
|
|
|
// // dd( $restaurant);
|
|
|
|
|
// return view('Admin.pages.manage_users.restaurants_app.restaurants_users', compact('restaurant'));
|
|
|
|
|
// } catch (Exception $e) {
|
|
|
|
|
// Log::error("Manage Voucher Page Not Load " . $e->getMessage());
|
|
|
|
|
// return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// public function index_restraunt_users(Request $request)
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
|
|
// // try {
|
|
|
|
|
// // $activeQuery = $request->query('active');
|
|
|
|
|
|
|
|
|
|
// // if ($activeQuery == 1) {
|
|
|
|
|
// // $restaurant_users = IamPrincipal::with('getresturant')->where('principal_type_xid', 4)->where('is_active', 1)->orderBy('created_at', 'desc')->get();
|
|
|
|
|
// // } else if ($activeQuery == 0 && $activeQuery != null) {
|
|
|
|
|
// // $restaurant_users = IamPrincipal::with('getresturant')->where('principal_type_xid', 4)->where('is_active', '0')->orderBy('created_at', 'desc')->get();
|
|
|
|
|
// // } else {
|
|
|
|
|
// // $restaurant_users = IamPrincipal::with('getresturant')->where('principal_type_xid', 4)->orderBy('created_at', 'desc')->get();
|
|
|
|
|
// // // dd($restaurant_users);
|
|
|
|
|
// // }
|
|
|
|
|
// // foreach ($restaurant_users as $user) {
|
|
|
|
|
// // $restaurantIds = $user->getresturant->pluck('restaurant_xid')->toArray();
|
|
|
|
|
// // // $user->vouchers = ManageVoucherModel::whereIn('id', $restaurantIds)->get();
|
|
|
|
|
// // }
|
|
|
|
|
// // return view('Admin.pages.manage_users.restaurants_app.restaurants_users', compact('restaurant_users'));
|
|
|
|
|
// // } catch (Exception $e) {
|
|
|
|
|
// // Log::error("Manage Voucher Page Not Load " . $e->getMessage());
|
|
|
|
|
// // return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500);
|
|
|
|
|
// // }
|
|
|
|
|
|
|
|
|
|
// // $restaurant = ManageRestaurant::with('state')->latest()->get();
|
|
|
|
|
// // dd( $restaurant);
|
|
|
|
|
// return view('Admin.pages.manage_users.restaurants_app.restaurants_users');
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function index_restraunt_users(Request $request)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$activeQuery = $request->query('active');
|
|
|
|
|
|
|
|
|
|
if ($activeQuery == 1) {
|
|
|
|
|
$restaurant_users = IamPrincipal::with('getresturant')->where('principal_type_xid', 4)->where('is_active', 1)->orderBy('created_at', 'desc')->get();
|
|
|
|
|
} else if ($activeQuery == 0 && $activeQuery != null) {
|
|
|
|
|
$restaurant_users = IamPrincipal::with('getresturant')->where('principal_type_xid', 4)->where('is_active', '0')->orderBy('created_at', 'desc')->get();
|
|
|
|
|
} else {
|
|
|
|
|
$restaurant_users = IamPrincipal::with('getresturant')->where('principal_type_xid', 4)->orderBy('created_at', 'desc')->get();
|
|
|
|
|
// dd($restaurant_users);
|
|
|
|
|
}
|
|
|
|
|
foreach ($restaurant_users as $user) {
|
|
|
|
|
$restaurantIds = $user->getresturant->pluck('restaurant_xid')->toArray();
|
|
|
|
|
// $user->vouchers = ManageVoucherModel::whereIn('id', $restaurantIds)->get();
|
|
|
|
|
}
|
|
|
|
|
return view('admin.pages.manage_users.restaurants_app.restaurants_users', compact('restaurant_users'));
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
Log::error("Manage Voucher Page Not Load " . $e->getMessage());
|
|
|
|
|
return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function change_rest_user_status(Request $request)
|
2024-05-29 17:11:02 +05:30
|
|
|
{
|
2024-05-30 19:41:43 +05:30
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
DB::beginTransaction();
|
|
|
|
|
$status = IamPrincipal::find($request->rest_user_id);
|
|
|
|
|
$status->is_active = $request->status;
|
|
|
|
|
|
|
|
|
|
// Generate a random password
|
|
|
|
|
$randomPassword = \Str::random(8); // Adjust the length as per your requirements
|
|
|
|
|
|
|
|
|
|
// Set the password
|
|
|
|
|
$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);
|
|
|
|
|
}
|
2024-05-29 17:11:02 +05:30
|
|
|
}
|
|
|
|
|
}
|
2024-05-30 19:41:43 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
|