fill($request->input()); $payment->save(); if($request->input('invoices')) { $invoices = Invoice::whereIn('id', $request->input('invoices'))->get(); $payment->invoices()->saveMany($invoices); } event(new PaymentWasCreated($payment)); UpdateInvoicePayment::dispatchNow($payment); return $payment; } }