我正在使用laravel 5.8,我想在登录时创建客户的发票,这种情况是我要在登录时检查是否发票的到期日等于当前时间,因此请创建同一客户的新发票。这是我的代码
登录控制器
public function login(Request $req)
{
$this->validate($req, [
'email' => 'required',
'password' => 'required'
]);
if (\Auth::attempt(['email' => $req->email, 'password' => $req->password])) {
$today = Carbon::now()->format('Y-m-d');
$all = Invoice::where('due_date', $today)->get()
foreach($all as $row) {
$addinvoice = Invoice::create([
'customer_id' => $row->customer_id,
'account_title' => $row->account_title,
'slug' => str_slug($row->account_title),
'perpared_date' => $today,
'amount' => $row->amount,
]);
if ($row->due_date == '1 month') {
$interval = $today->addMonths()->format('Y-m-d');
}
if ($row->due_date == '3 month') {
$interval = $today->addMonths(3)->format('Y-m-d');
}
if ($row->due_date == '6 month') {
$interval = $today->addMonths(6)->format('Y-m-d');
}
if ($row->due_date == '12 month') {
$interval = $today->addMonths(12)->format('Y-m-d');
}
$addinvoice['due_date'] = $interval;
}
return redirect()->to('/admin/customers/list');
} else {
return redirect()->back()->with(['msg' => 'Invalid Email or Password']);
}
}
登录后出现错误
syntax error, unexpected 'foreach' (T_FOREACH)
可以帮我解决它吗?
你忘了这行的分号
$all = Invoice::where('due_date', $today)->get()
用分号->get()
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句