1 回答
TA贡献1839条经验 获得超15个赞
我正在尝试向选定的用户发送带有他们姓名的消息。假设我有两个用户 Ethan 和 Calvin,那么消息的开头应为 User1:(Hi, Ethan)、User2:(Hi, Calvin)。到目前为止,每个用户的消息就像(嗨,Ethan,Calvin)。我怎样才能解决这个问题?
刀刃
<form action="{{ route('mes.users') }}" method="POST">
@foreach($users as $user)
<textarea name="message"></textarea>
<input type="checkbox" name="phone[]" @if(!old() || old('phone') == 'true') @endif value="
{{ $user->phone }}">
<input type="checkbox" name="name[]" value="{{ $user->name }}"/>
<button type="submit" class="btn btn-primary">
send Message
</button>
@endforeach
</form>
控制器
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';
}
- 1 回答
- 0 关注
- 76 浏览
添加回答
举报