У меня возникают некоторые проблемы с работой моих проектов Laravel, не удается выполнить расчет расстояния, а также кнопка запроса, сообщающая об ошибке Что-то пошло не так при отправке запроса. Пожалуйста, попробуйте еще раз. в чем может быть проблема
спасибо заранее
введите описание изображения здесь
вот мой код
publi c функция send_request (запрос $ request) {
$this->validate($request, [
's_latitude' => 'required|numeric',
'd_latitude' => 'required|numeric',
's_longitude' => 'required|numeric',
'd_longitude' => 'required|numeric',
'service_type' => 'required|numeric|exists:service_types,id',
'promo_code' => 'exists:promocodes,promo_code',
'distance' => 'required|numeric',
'use_wallet' => 'numeric',
'payment_mode' => 'required|in:CASH,CARD,PAYPAL',
'card_id' => ['required_if:payment_mode,CARD','exists:cards,card_id,user_id,'.Auth::user()->id],
]);
Log::info('New Request from User: '.Auth::user()->id);
Log::info('Request Details:', $request->all());
$ActiveRequests = UserRequests::PendingRequest(Auth::user()->id)->count();
if($ActiveRequests > 0) {
if($request->ajax()) {
return response()->json(['error' => trans('api.ride.request_inprogress')], 500);
} else {
return redirect('dashboard')->with('flash_error', 'Already request is in progress. Try again later');
}
}
if($request->has('schedule_date') && $request->has('schedule_time')){
$beforeschedule_time = (new Carbon("$request->schedule_date $request->schedule_time"))->subHour(1);
$afterschedule_time = (new Carbon("$request->schedule_date $request->schedule_time"))->addHour(1);
$CheckScheduling = UserRequests::where('status','SCHEDULED')
->where('user_id', Auth::user()->id)
->whereBetween('schedule_at',[$beforeschedule_time,$afterschedule_time])
->count();
if($CheckScheduling > 0){
if($request->ajax()) {
return response()->json(['error' => trans('api.ride.request_scheduled')], 500);
}else{
return redirect('dashboard')->with('flash_error', 'Already request is Scheduled on this time.');
}
}
}
$distance = Setting::get('provider_search_radius', '10');
$latitude = $request->s_latitude;
$longitude = $request->s_longitude;
$service_type = $request->service_type;
$Providers = Provider::with('service')
->select(DB::Raw("(6371 * acos( cos( radians('$latitude') ) * cos( radians(latitude) ) * cos( radians(longitude) - radians('$longitude') ) + sin( radians('$latitude') ) * sin( radians(latitude) ) ) ) AS distance"),'id')
->where('status', 'approved')
->whereRaw("(6371 * acos( cos( radians('$latitude') ) * cos( radians(latitude) ) * cos( radians(longitude) - radians('$longitude') ) + sin( radians('$latitude') ) * sin( radians(latitude) ) ) ) <= $distance")
->whereHas('service', function($query) use ($service_type){
$query->where('status','active');
$query->where('service_type_id',$service_type);
})
->orderBy('distance')
->get();
// List Providers who are currently busy and add them to the filter list.
if(count($Providers) == 0) {
if($request->ajax()) {
// Push Notification to User
return response()->json(['message' => trans('api.ride.no_providers_found')]);
}else{
return back()->with('flash_success', 'No Providers Found! Please try again.');
}
}
try{
$details = "https://maps.googleapis.com/maps/api/directions/json?origin=".$request->s_latitude.",".$request->s_longitude."&destination=".$request->d_latitude.",".$request->d_longitude."&mode=driving&key=".Setting::get('map_key');
$json = curl($details);
$details = json_decode($json, TRUE);
$route_key = $details['routes'][0]['overview_polyline']['points'];
$UserRequest = new UserRequests;
$UserRequest->booking_id = Helper::generate_booking_id();
$UserRequest->user_id = Auth::user()->id;
$UserRequest->current_provider_id = $Providers[0]->id;
$UserRequest->service_type_id = $request->service_type;
$UserRequest->payment_mode = $request->payment_mode;
$UserRequest->status = 'SEARCHING';
$UserRequest->s_address = $request->s_address ? : "";
$UserRequest->d_address = $request->d_address ? : "";
$UserRequest->s_latitude = $request->s_latitude;
$UserRequest->s_longitude = $request->s_longitude;
$UserRequest->d_latitude = $request->d_latitude;
$UserRequest->d_longitude = $request->d_longitude;
$UserRequest->distance = $request->distance;
if(Auth::user()->wallet_balance > 0){
$UserRequest->use_wallet = $request->use_wallet ? : 0;
}
$UserRequest->assigned_at = Carbon::now();
$UserRequest->route_key = $route_key;
if($Providers->count() <= Setting::get('surge_trigger') && $Providers->count() > 0){
$UserRequest->surge = 1;
}
if($request->has('schedule_date') && $request->has('schedule_time')){
$UserRequest->schedule_at = date("Y-m-d H:i:s",strtotime("$request->schedule_date $request->schedule_time"));
}
$UserRequest->save();
Log::info('New Request id : '. $UserRequest->id .' Assigned to provider : '. $UserRequest->current_provider_id);
// update payment mode
User::where('id',Auth::user()->id)->update(['payment_mode' => $request->payment_mode]);
if($request->has('card_id')){
Card::where('user_id',Auth::user()->id)->update(['is_default' => 0]);
Card::where('card_id',$request->card_id)->update(['is_default' => 1]);
}
(new SendPushNotification)->IncomingRequest($Providers[0]->id);
foreach ($Providers as $key => $Provider) {
$Filter = new RequestFilter;
// Send push notifications to the first provider
// incoming request push to provider
$Filter->request_id = $UserRequest->id;
$Filter->provider_id = $Provider->id;
$Filter->save();
}
if($request->ajax()) {
return response()->json([
'message' => 'New request Created!',
'request_id' => $UserRequest->id,
'current_provider' => $UserRequest->current_provider_id,
]);
}else{
return redirect('dashboard');
}
} catch (Exception $e) {
if($request->ajax()) {
return response()->json(['error' => trans('api.something_went_wrong')], 500);
}else{
return back()->with('flash_error', 'Something went wrong while sending request. Please try again.');
}
}
}