我正在尝试ENV
从用户端动态设置一些值。我想使用多个短信网关服务,以便用户可以使用多个网关中的任何一个。多个服务有不同api
的,sid
或token
。我将这些服务提供商凭据保存在sms_gateways
表中,并尝试使用此表中的这些凭据,而不是控制器方法中的手动代码。但是,像这样使用我遇到了麻烦。我正在尝试这样的事情 -
public function storeSMS(Request $request)
{
$smsGateway = $request->smsgatewayname;
if ($smsGateway['value'] == 'Twilio') {
$twilio = SmsGateway::where('name', 'Twilio')->first();
//return $twilio->sid;
//*here I want to use $twilio->sid value inside env. Is it possible?
$sid = env( 'TWILIO_SID' );
$token = env( 'TWILIO_TOKEN' );
$client = new Client($sid, $token);
$request->validate([
'text'=>'required',
'contact'=>'required'
]);
$now = Carbon::now();
$datetime = explode(' ', $now);
$numbers_in_arrays = explode( ',' , $request->contact );
$message = $request->text;
$count = 0;
foreach( $numbers_in_arrays as $number )
{
$count++;
$client->messages->create(
'+'.$number,
[
'from' => env( 'TWILIO_FROM' ),
'body' => $message,
]
);
$outbox = new SmsOutbox();
$outbox->contact = '+'.$number;
$outbox->text = $message;
$outbox->send_date = $datetime[0];
$outbox->send_time = $datetime[1];
$outbox->is_send = 1;
$outbox->save();
}
}
return;
}