diff --git a/app/Http/Controllers/API/SyncController.php b/app/Http/Controllers/API/SyncController.php index 01bb071..23b9e89 100644 --- a/app/Http/Controllers/API/SyncController.php +++ b/app/Http/Controllers/API/SyncController.php @@ -7,7 +7,6 @@ use App\Mail\SendFlyerFailed; use App\Models\AppUsers; use App\Models\Contacts; use App\Models\Data; -use Google\Type\Date; use GuzzleHttp\Exception\ClientException; use Illuminate\Http\Request; use Illuminate\Support\Facades\Mail; @@ -24,7 +23,7 @@ class SyncController extends Controller public function getContacts(Request $request) { $userId = $request->userId; - $this->syncContacts(json_decode($request->contacts), $userId); + $this->syncContacts($request->contacts, $userId); return new \App\Http\Resources\ContactsCollection(\App\Models\Contacts::where('user_id', $userId)->get()); } @@ -121,6 +120,7 @@ class SyncController extends Controller } private function syncContacts($contacts, $userId) { + $contacts = json_decode (json_encode ($contacts), FALSE); foreach ($contacts as $contact) { if ($contact->to_delete === true) { $tmp = Contacts::where([ @@ -154,7 +154,7 @@ class SyncController extends Controller $tmp->firstname = $contact->firstname; $tmp->company = $contact->company; $tmp->address = $contact->address; - $tmp->phone = $contact->phone; + $tmp->phone = empty($contact->phone) ? "" : $contact->phone; $tmp->products = $contact->products; $tmp->notes = $contact->notes; $tmp->visits = $contact->visits; @@ -172,7 +172,7 @@ class SyncController extends Controller $tmp->firstname = $contact->firstname; $tmp->company = $contact->company; $tmp->address = $contact->address; - $tmp->phone = $contact->phone; + $tmp->phone = empty($contact->phone) ? "" : $contact->phone; $tmp->products = $contact->products; $tmp->notes = $contact->notes; $tmp->visits = $contact->visits; diff --git a/routes/api.php b/routes/api.php index 7eb56c1..004cb95 100644 --- a/routes/api.php +++ b/routes/api.php @@ -15,7 +15,7 @@ use Illuminate\Http\Request; Route::group(['middleware' => 'api.token'], function () { Route::get('users', 'API\SyncController@getUsers'); - Route::get('contacts', 'API\SyncController@getContacts'); + Route::post('contacts', 'API\SyncController@getContacts'); Route::get('directories', 'API\SyncController@getDirectories'); Route::get('documents', 'API\SyncController@getDocuments'); Route::get('version', 'API\SyncController@getVersion');