I can't see the rest of the code to be sure but my guess is you're using a closure which removes $member_id
form the scope of your loop. If that's the case, then the use keyword will allow you to access variables outside of the scope of the closure. For example -
function () use ($member_id) { // pass $member_id into scope of closure
foreach ($request->moreFields as $key => $value) {
Permit::create([
'member_id' => $member_id,
'license_type' => $request->license_type[$i],
'license_number' => $request->license_number[$i],
'registration_date' => $request->registration_date[$i],
'expiration_date' => $request->expiration_date[$i],
]);
}
};
* Be the first to Make Comment