我正在使用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>
答案 0 :(得分:0)
将默认媒体表迁移文件编辑为:
Schema::create('media', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('model_type');
$table->uuid('model_id');
$table->uuid('uuid')->nullable();
$table->string('collection_name');
$table->string('name');
$table->string('file_name');
$table->string('mime_type')->nullable();
$table->string('disk');
$table->string('conversions_disk')->nullable();
$table->unsignedBigInteger('size');
$table->json('manipulations');
$table->json('custom_properties');
$table->json('responsive_images');
$table->unsignedInteger('order_column')->nullable();
$table->nullableTimestamps();
});
}