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)
});
},