问题描述
我可以更新我的电子邮件和密码,但我无法更新我的个人资料照片。 这是我写的代码。我不知道我哪里做错了,你能帮我吗?我想我错过了 Fortify 中 ProfileinformationController.PHP 的一些东西
<form method="POST" action="{{ route('user-profile-information.update') }}" enctype="multipart/form-data">
@csrf
@method('PUT')
<div class="form-group row">
<label for="name" class="col-md-4 col-form-label text-md-right">{{ __('Photo') }}</label>
<div class="row">
<div class="form-group col-md-6">
<label for="exampleInputName1">Profile Image Upload</label>
<input type="file" name="profile_photo_path" class="form-control-file" id="profile_photo_path">
</div>
</div> <!-- End Row -->
</div>
<div class="form-group row">
<label for="name" class="col-md-4 col-form-label text-md-right">{{ __('Name') }}</label>
<div class="col-md-6">
<input id="name" type="name" class="form-control @error('name') is-invalid @enderror" name="name" value="{{ old('name') ?? auth()->user()->name }}" required autocomplete="name" autofocus>
@error('name')
<span class="invalid-Feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
</div>
<div class="form-group row">
<label for="email" class="col-md-4 col-form-label text-md-right">{{ __('E-Mail Address') }}</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control @error('email') is-invalid @enderror" name="email" value="{{ old('email') ?? auth()->user()->email }}" required autocomplete="email" autofocus>
@error('email')
<span class="invalid-Feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
</div>
<div class="mb-0 form-group row">
<div class="col-md-8 offset-md-4">
<button type="submit" class="btn btn-primary">
{{ __('Update Profile') }}
</button>
</div>
</div>
</form>
解决方法
看来,如果您使用的是 Laravel Fortify 的无头版本,它似乎无法上传个人资料图片。迁移不包括个人资料照片的属性,并且控制器中的代码中没有与上传个人资料照片相关的任何内容。此外,文档没有提到能够上传个人资料照片。 https://laravel.com/docs/8.x/fortify 除非我遗漏了什么,否则必须在您这边实施。
class ProfileInformationController extends Controller
{
/**
* Update the user's profile information.
*
* @param \Illuminate\Http\Request $request
* @param \Laravel\Fortify\Contracts\UpdatesUserProfileInformation $updater
* @return \Illuminate\Http\Response
*/
public function update(Request $request,UpdatesUserProfileInformation $updater)
{
$updater->update($request->user(),$request->all());
return $request->wantsJson()
? new JsonResponse('',200)
: back()->with('status','profile-information-updated');
}
}