Level 75
Do you have enctype="multipart/form-data
1 like
I want to upload a file in an edit page with this code
This is the HTML
<input id="attachment" type="file"
class="form-control @error('attachment') is-invalid @enderror"
name="attachment" value="{{ old('attachment') }}" required
autocomplete="attachment" autofocus>
And in the controller this
if ($request->hasFile('attachment')) {
$filenameWithExt = $request->file('attachment')->getClientOriginalExtension();
$filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);
$extension = $request->file('attachment')->getClientOriginalExtension();
$fileNameToStore = $filename . '_' . time() . '.' . $extension;
$request->file('attachment')->storeAs('storage/files', $fileNameToStore);
} else {
$fileNameToStore = 'No File';
}
BUt when I submit the page, it stores with No File, so I cannot upload and if I Dump and Die the request is see the filename. Help me
Do you have enctype="multipart/form-data
Please or to participate in this conversation.