search state API

This commit is contained in:
sayliraut
2024-06-19 17:26:37 +05:30
parent 52f7299d6a
commit 47ea603c10
3 changed files with 38 additions and 0 deletions

View File

@@ -269,4 +269,20 @@ class AuthController extends Controller
return response()->json(__('something_went_wrong'), 500);
}
}
/**
* Created By : Sayli Raut
* Created at : 19 June 2024
* Use : Search State.
*/
public function searchState(Request $request)
{
try {
return $this->AuthServices->searchState($request);
} catch (\Exception $ex) {
Log::error("Login API Failed: " . $ex->getMessage());
return jsonResponseWithErrorMessage(__('error_message.something_went_wrong'), 500);
}
}
}

View File

@@ -310,4 +310,24 @@ class AuthServices
return jsonResponseWithErrorMessageApi(__('auth.authentication_failed'), 403);
}
}
public function searchState($request)
{
try {
$searchQuery = $request->input('search_data');
$query = ManageState::select('id', 'name')->where('is_active', 1);
if ($searchQuery) {
$query->where(function ($q) use ($searchQuery) {
$q->where('name', 'like', '%' . $searchQuery . '%');
});
}
$restaurants = $query->get();
return jsonResponseWithSuccessMessageApi(__('auth.data_fetched_successfully'), $restaurants, 200);
} catch (\Exception $e) {
Log::error("An error occurred in " . __METHOD__ . ": " . $e->getMessage());
return response()->json(__('something_went_wrong'), 500);
}
}
}

View File

@@ -24,6 +24,8 @@ Route::middleware(['customerApiBasicAuth'])->group(function () {
Route::post('/v1/password/verify-otp', [AuthController::class, 'verifyOtpForgotPassword']);
Route::post('/v1/change-password', [AuthController::class, 'changePassword']);
Route::post('/v1/resend-otp', [AuthController::class, 'resendOtp']);
Route::post('/v1/search-state', [AuthController::class, 'searchState']);
Route::group(['middleware' => ['customer.jwt.verify']], function () {