I have a pivot table that gets populated by another controller.
It has:
user_id, team_form_id, file_upload.
The user_id and file_upload gets populated by another controller. I need to get the team_form_id populated by a form that is submitted. The user uploads multiple files and it gets stored, the person then submits the form - I have had to use 2 controllers as the uploads are chunked.
I would like to check where the user_id is = to Auth::user()->id and where the team_form_id is null to be populated with the form id that is being submitted:
public function store(Request $request)
{
$teamform = new TeamForm;
$teamform->team_form_id = $request->team_form_id;
$teamform->teamupload = $request->teamupload;
$teamform->user_id = Auth::user()->id;
$teamform->save();
if ($teamform->save()) {
$teamuser = Auth::user()->id;
$teamform->teamlog()->sync($teamuser);
}
return redirect(route('team-form.index'))->with('success', 'Form added successfully');
}
The model for the file upload is TeamFormFIle.
I have tried the below:
if ($teamform->save()) {
$files = TeamFormFile::find('user_id' == Auth::user()->id);
if ($files->team_form_id == null) {
foreach($files as $file) {
$file->team_form_id = $teamform->id;
$file->save();
}
}
}
So basically loop through the records find the user that is currently logged in and submit the form id to the team_form_id that are null.