/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $input = $request->all(); $existing = Integration::where(['api_type' => $request->api_type])->get(); $existing = isset($existing[0]) ? $existing[0] : null; if ($existing) { $existing->fill($input)->save(); } else { Integration::create($input); } return $this->index(); }
/** * Get the api class name * * @param [string] $type [description] * @return [type] [description] */ public static function getApi($type) { $integration = Integration::where(['api_type' => $type])->get(); if ($integration) { $apiConfig = $integration[0]; $className = $apiConfig->name; call_user_func_array(['App\\' . $className, 'initialize'], [$apiConfig]); $apiInstance = call_user_func_array(['App\\' . $className, 'getInstance'], []); return $apiInstance; } throw new \Exception('The user has no integrated APIs'); }