Heei,我只是使用 邀请人 创建一些 预订房间 网络。该表看起来像那样
关于 预订房间 的数据将被插入jadwal_meetings
表格以及有关 邀请人 的数据将插入invites
表。控制器如下所示
控制器
public function save_schedule(Request $save)
{
$create = new jadwal_meeting;
$create->nama_meeting = $save->input('nama_meeting');
$create->tanggal = $save->input('tanggal_meeting');
$create->jam_mulai = $save->input('jam_mulai');
/*and some other field*/
$id_jadwal = $create->id;
$create->save();
// looping email_user
$emails = $save->input('email');
foreach ($emails as $email)
{
// Insert to invites table
$email = new invites;
$email->id_meeting = $save->$id_jadwal;
$email->invite_people = $save->input('email');
$email->save();
}
return redirect()->route('user_home');
}
我只是创建了html 阴影输入元素,用于收集 邀请人 这样的值
Html + Jquery
<input type="text" name="nama_meeting">
<input type="text" name="tanggal_meeting">
<input type="email" name="people_invited">
<ul class="people_added"></ul>
$("[name='people_invited']").keyup(function (e) {
if (e.key == 'Enter' && ($(this).val() !== '')) {
var orang_yg_diinvite = $(this).val();
$("ul.people_added").append("<li>" + orang_yg_diinvite +"</li>");
$("ul.people_added").append("<input type='hidden' name='email[]' value='" + orang_yg_diinvite + "'>");
}
});
结果
但这不行,我得到这样的错误
数组到字符串转换(SQL:插入
invites
(id_meeting
,invite_people
,updated_at
,created_at
)值(, people1 @email.com,2018-04-26 04:37:50,2018-04-26 04:37:50))
如何解决这个错误,请帮帮我:)。
答案 0 :(得分:4)
您只需更改控制器代码,如下所示。
public function save_schedule(Request $save)
{
$create = new jadwal_meeting;
$create->nama_meeting = $save->input('nama_meeting');
$create->tanggal = $save->input('tanggal_meeting');
$create->jam_mulai = $save->input('jam_mulai');
/*and some other field*/
$id_jadwal = $create->id;
$create->save();
// looping email_user
$emails = $save->input('email');
foreach ($emails as $email)
{
// Insert to invites table
$invite = new invites;
$invite->id_meeting = $id_jadwal; // changes
$invite->invite_people = $email; // changes
$invite->save();
}
return redirect()->route('user_home');
}
谢谢,
答案 1 :(得分:2)
你犯了一些错误。请尝试此代码。
$create = new jadwal_meeting;
$create->nama_meeting = $save->input('nama_meeting');
$create->tanggal = $save->input('tanggal_meeting');
$create->jam_mulai = $save->input('jam_mulai');
$create->save();
$id_jadwal = $create->id;
$emails = $save->input('email');
foreach ($emails as $email)
{
// Insert to invites table
$invite = new invites;
$invite->id_meeting = $id_jadwal;
$invite->invite_people = $email;
$invite->save();
}