I'm working on a Laravel web application that should upload .pdf files from a form to database, with some specific information inserted by the user in the same form where he uploads the file. Everything works perfectly, but in the table on my database, I have two separated rows created. First one contains just file_name (Original Client name) and file_size (Original Client size), but other form information set to their default values (NULL), in the second row I have the opposite, additional form data that is set correctly, but the file_name and file_size are set to default (NULL) here is my function in controller block
public function auteurAdd(Request $request)
{
$parameters = $request->except(['_token']);
$conference = new Conference();
$conference->titre = $parameters['titre'];
$conference->theme = $parameters['theme'];
$conference->track = $parameters['track'];
// upload file into database
if ($request->hasFile('file')) {
$filename = $request->file->getClientOriginalName();
$filesize = $request->file->getClientSize();
$file = new Conference;
$file->file_name = $filename;
$file->file_size = $filesize;
$file->save();
}
$conference->save();
return redirect()->route('auteurHome');
}
and this is the form
<form method="post" action="{{route('auteurAdd')}}" class="text-center border border-light p-5"
enctype="multipart/form-data">
{{ csrf_field() }}
<p class="h4 mb-4">Upload d'une conférence</p>
<div class="form-group">
<input name="titre" class="form-control mb-4" placeholder="Titre"/>
<input name="theme" class="form-control mb-4" placeholder="Thème"/>
<input name="track" class="form-control mb-4" placeholder="Track"/>
</div>
<div class="btn btn-mdb-color btn-rounded float-left">
<input type="file" name="file">
</div>
<button class="btn btn-info btn-block my-4" type="submit">Envoyer</button>
</form>
Try like this: