<?php
 namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use Illuminate\Validation\Rule; use Session; use File; use Config; use Illuminate\Http\Response; use Storage; class Synchronization extends Controller { public function __construct() { } public function sync_live(Request $request) { $live_server_access_key = Config::get('constants.live_server_access_key'); if($request->access_key == $live_server_access_key) { if($request->call_type == 'LOCAL_TO_LIVE') { foreach($request->sync_data as $query) { if($query['type'] == 'insert') { DB::table($query['table'])->insert($query['data']); } if($query['type'] == 'update') { DB::table($query['table'])->where($query['column'],$query['value'])->update($query['data']); } if($query['type'] == 'delete') { DB::table($query['table'])->where($query['column'],$query['value'])->delete(); } } empty_sync_file(); echo json_encode(array('call_status' => 'SUCCESS')); } if($request->call_type == 'LIVE_TO_LOCAL') { $synced_data = get_sync_data(); if($synced_data == 'NO_DATA_TO_SYNC') { $response_array = array( 'call_status' => 'NO_DATA_TO_SYNC', 'sync_data' => array() ); echo json_encode($response_array); } else { $synced_data = json_decode($synced_data,true); $response_array = array( 'call_status' => 'SUCCESS', 'sync_data' => $synced_data ); empty_sync_file(); echo json_encode($response_array); } } } else { echo json_encode(array('call_status' => 'ACCESS_DENIED')); } } }