diff --git a/app/Http/Controllers/ClientApiController.php b/app/Http/Controllers/ClientApiController.php index bbe0f9fde298..816ce9b9eaa7 100644 --- a/app/Http/Controllers/ClientApiController.php +++ b/app/Http/Controllers/ClientApiController.php @@ -82,8 +82,21 @@ class ClientApiController extends BaseAPIController */ public function store(CreateClientRequest $request) { - $client = $this->clientRepo->save($request->input()); - + if ($request->has('filter_by_email')) { + + $email = $request->get('filter_by_email'); + $client = Client::whereHas('contacts', function ($query) use ($email) { + $query->where('email', $email); + })->with('contacts')->first(); + + if (is_null($client)) { + $client = $this->clientRepo->save($request->input()); + } + + } else { + $client = $this->clientRepo->save($request->input()); + } + $client = Client::scope($client->public_id) ->with('country', 'contacts', 'industry', 'size', 'currency') ->first(); diff --git a/app/Http/routes.php b/app/Http/routes.php index e0ded5dd46e3..4bd84629f0c6 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -209,7 +209,7 @@ Route::group(['middleware' => 'auth'], function() { // Route groups for API Route::group(['middleware' => 'api', 'prefix' => 'api/v1'], function() { - Route::resource('ping', 'ClientApiController@ping'); + Route::get('ping', 'ClientApiController@ping'); Route::post('login', 'AccountApiController@login'); Route::get('static', 'AccountApiController@getStaticData'); Route::get('accounts', 'AccountApiController@show');