my project have some API will call 3rd party, and the 3rd party api request some parameter like user, password, i put those parameter in .env.
i set those parameter before i call the 3rd api, so every 3rd party api call will init those 3rd party parameter. i have several controller will call the 3rd api call so have many duplicate code to init 3rd parameter function.
my idea is to move the params init code to the middleware, but is there a more correct way like use singleton for these parameter ? what i am doing now in one of the controller is like
class XXXDataController extends BaseController
public function index(Request $request)
{
$params = new Params([
'authParams' =>
'userId' => env('xxx3rd_user_id'),
'password' => env('xxx3rd_pass'),
xxx,
xxx,
...
],
$client = new Client($params);
$client->requestSent();
...
...