0
我有一個方法來處理來自動態表單的請求。用循環laravel保存到數組
public function step2(Request $request)
{
$this->validate($request, [
'title.*' => 'required',
'f_name.*' =>'required',
'l_name.*' =>'required',
'dob_month.*' =>'required',
'dob_day.*' =>'required',
'dob_year.*' =>'required',
'gender.*' =>'required',
'email.*' =>'required',
'contact.*' =>'required',
'address1.*' =>'required',
'address2.*' =>'required',
'town.*' =>'required',
'state.*' =>'required',
'mailbox.*' =>'required',
'insurance.*' =>'required',
]);
$data = array(
for ($i=0; $i <$request->limit ; $i++){
"title$i" => $request->title[$i],
"f_name$i" => $request->f_name[$i],
if (!isEmpty($request->m_name)) {
"m_name$i" => $request->m_name[$i],
}
"l_name$i" => $request->l_name[$i],
"dob_month$i" => $request->dob_month[$i],
"dob_day$i" => $request->dob_day[$i],
"dob_year$i" => $request->dob_year[$i],
"gender$i" => $request->gender[$i],
"email$i" => $request->email[$i],
"contact$i" => $request->contact[$i],
"address1$i" => $request->address1[$i],
if (!isEmpty($request->m_name)) {
"address2$i" => $request->address2[$i],
}
"town$i" => $request->town[$i],
"mailbox$i" => $request->mailbox[$i],
"insurance$i" => $request->insurance[$i],
}
Mail::send('emails.contact', $data, function($message) use ($data){
$message->from(''[email protected]);
$message->to('[email protected]');
$message->subject("!!New Mail!!");
});
);
return view('success');
}
我試圖保存所有傳入的請求在數組中使用for循環爲了發送它作爲電子郵件。但我得到的錯誤是 Parse error: syntax error, unexpected 'for' (T_FOR), expecting ')'
。這個問題最好的辦法是什麼?
您無法在Array內運行循環。這就是它給出錯誤的原因。嘗試在數組外使用for循環來向數組填充數組@@ tanja-forsberg –
您應該在數組外循環,並追加到for循環中的數組 – linktoahref
請檢查 - > $ message-> from('sender @ demo.com); –