Below example is of checking Order Status from Shiprocket and updating it in the database hourly. Execute the below command: php artisan make:command OrderStatusCheck--command=orderstatuscheck:cron

]), ])->wait(); if($g_request->getStatusCode() == 200) { $shiprocketResponse = json_decode($g_request->getBody()); } if($shiprocketResponse != null) { if(current($shiprocketResponse) == false) //array el 0 returns false { Log::info('OrderStatusCheck CRON shiprocketResponse response false, DATE: '.date("Y-m-d h:i:s")); //return response()->json(['status'=>'Shipment not picked up or Shipment has not been scheduled for pickup'], 400); } elseif(current($shiprocketResponse)!= false)//If successfully getting a shipment pickup response { $order = OrderShiprocket::where('shiprocket_awb', $shipment->shiprocket_awb)->first(); $order->update([ 'shiprocket_status' => current(current($shiprocketResponse)->tracking_data->shipment_track)->current_status, 'edd' => current(current($shiprocketResponse)->tracking_data->shipment_track)->edd, 'track_url' => current($shiprocketResponse)->tracking_data->track_url, //For saving Track URL ]); }} if($shiprocketResponse == null) { Log::info('OrderStatusCheck CRON shiprocketResponse response null, DATE: '.date("Y-m-d h:i:s")); //return response()->json(['status'=>'No response recieved from Shiprocket, must be issue with AWB'], 400); } // Log::info('OrderStatusCheck CRON Iterating , DATE: '.date("Y-m-d h:i:s")); }} } catch (GuzzleException $e1) { Log::info('OrderStatusCheck CRON GuzzleException, DATE: '.date("Y-m-d h:i:s").' '.$e1->getMessage()); } Log::info('OrderStatusCheck CRON Iteration Completed, DATE: '.date("Y-m-d h:i:s")); } // Log::info('OrderStatusCheck CRON running , DATE: '.date("Y-m-d h:i:s")); // return 0; }} For starting CRON on Server: php artisan schedule:run * * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners