我正在使用 spaties 媒体库来处理我的图像。我试图允许用户以多部分形式上传图像。
尝试继续时出现此错误
当前请求在名为的键中没有文件
pic
它在请求中,就像我执行此操作时一样。
dd($validatedData)
这是我的控制器功能
public function postStep2(Request $request){
$validatedData = $request->validate([
'pic' => 'required'
]);
if(empty($request->session()->get('user'))){
$user = new User();
$user->addMediaFromRequest('pic')->toMediaCollection('profile_image');
$request->session()->put('user', $user);
}else{
$user = $request->session()->get('user');
$user->addMediaFromRequest('pic')->toMediaCollection('profile_image');
$request->session()->put('user', $user);
}
return redirect('/step3');
}
这是我的看法
<div class="user-icon--uploader-wrapper">
<div class="previews"></div>
<input type="file" name="pic" id="pic">
</div>
这是完整的表格
<form action="/step2" id="signupForm" method="POST" class="register-form" enctype="multipart/form-data">
{{ csrf_field() }}
<h4 class="step-heading btn-margin">Step 2 - Verification</h4>
<div class="input--file youth-photo">
<h3 class="input--file__title">Photo of Your Passport </h3>
<div class="user-icon--uploader-wrapper">
<div class="previews"></div>
<input type="file" name="pic" id="pic">
</div>
<span class="personalphoto">Only a photo of your passport displaying your photo and information will be permitted.</span>
</div>
<div class="input--submit">
<button type="submit" class="btn-pill--filled complete-step">Go To The Next Step</button>
<div class="youth-registration__steps-list">
<p>
Step 2 of 3 <span>Completed</span>
</p>
</div>
</div>
</form>