I'm trying to send a message to selected users with their names. So let's say I have two users Ethan and Calvin then the message should start like User1:(Hi, Ethan), User2:(Hi, Calvin). So far the message is like (Hi, Ethan,Calvin) for every user. How can I fix this?
Blade
<form action="" method="POST">
@foreach($users as $user)
<textarea name="message" ></textarea>
<input type="checkbox" name="phone[]" @if(!old() || old('phone') == 'true') @endif value="
">
<input type="checkbox" name="name[]" value=""/>
<button type="submit" class="btn btn-primary">
send Message
</button>
@endforeach
</form>
Controller
public function message(Request $request)
{
$message = $request->input('message');
$postData = $request->all();
foreach ($postData['phone'] as $index => $value) {
$postData['phone'][$index] = Str::replaceFirst('1','965',$value);
}
foreach($postData['name'] as $index => $names){
$postData['name'][$index] = $names;
}
$phone_number = implode(',', $postData['phone']);
$name = implode(',', $postData['name']);
$send_message = new MyHelper();
$message = "Hi, $name $message";
$send_message->sendMessage($phone_number,$message);
return 'success';
}
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/33fQdht
via IFTTT
Aucun commentaire:
Enregistrer un commentaire