如何在 'if' 条件下使用 foreach,Laravel 5.8

How to use foreach in 'if' condition, Laravel 5.8

我正在使用 laravel 5.8 我想在登录时创建客户发票, 场景是我想在登录时检查是否发票的到期日期等于当前时间,因此创建同一客户的新发票。 这是我的代码

Login Controller

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()

加上分号