无法在表中选定的联系人中发送多个SMS
当我尝试根据管理面板表中的选定联系人发送多个SMS时,我的功能有问题,当我单击“发送”按钮时,仅发送一张SMS。顺便说一句,我正在使用Laravel,Vuejs和Axios。
这是我在控制器中的功能:
public function sendMessage(Request $request, $id){
date_default_timezone_set('Asia/Japan');
$secret = $request->input('secret');
$deviceID = $request->input('deviceID');
$time = time();
$secretMd5 = md5($secret.$time);
$single_user_id = explode(',' , $id);
foreach ($single_user_id as $id) {
$number = Contact::find($id)->where('id', $id)->value('mobile_number');
$message = $request->input('message');
}
return file_get_contents("https://"server"/?to=".urlencode(trim($number))."&text=".urlencode($message)."&secret=$secretMd5&time=$time&deviceID=".$deviceID);
}
这是我在api.php中的路线,
Route::post('send/{id}', 'App\Http\Controllers\ContactController@sendMessage');
这是我在vue.js中的方法:
Send(selected) {
const vm = this;
axios.post("/api/send/" + selected, this.sms)
.then(response => {
vm.getContact();
this.select_all = false;
this.selected = [];
this.sms.secret = null;
this.sms.deviceID = null;
this.sms.message = null;
})
.catch(function (error) {
console.log(error)
});
},
I have a problem with my function when i try to send multiple sms based on selected contacts in the table of my admin panel when i click send button, it only send one sms. By the way i am using laravel and vuejs and axios.
Here's is my function in my controller:
public function sendMessage(Request $request, $id){
date_default_timezone_set('Asia/Japan');
$secret = $request->input('secret');
$deviceID = $request->input('deviceID');
$time = time();
$secretMd5 = md5($secret.$time);
$single_user_id = explode(',' , $id);
foreach ($single_user_id as $id) {
$number = Contact::find($id)->where('id', $id)->value('mobile_number');
$message = $request->input('message');
}
return file_get_contents("https://"server"/?to=".urlencode(trim($number))."&text=".urlencode($message)."&secret=$secretMd5&time=$time&deviceID=".$deviceID);
}
Here is my route in api.php
Route::post('send/{id}', 'App\Http\Controllers\ContactController@sendMessage');
Here is my method in vue.js:
Send(selected) {
const vm = this;
axios.post("/api/send/" + selected, this.sms)
.then(response => {
vm.getContact();
this.select_all = false;
this.selected = [];
this.sms.secret = null;
this.sms.deviceID = null;
this.sms.message = null;
})
.catch(function (error) {
console.log(error)
});
},
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的控制器方法中有错误,
如果您需要更清晰的代码,则可以使用:
在VUE中:
You have error in your controller method
If you want more clear code then you can use :
and in vue :