这是我的edit.blade.php,其中显示了用于更新用户个人资料并上传其图像的表格
<!-- form start -->
<form action="{{ route('profile.update') }}" method="POST" role="form" enctype="multipart/form-data">
@csrf
<div class="card-body">
@if (session('status'))
<div class="alert alert-success" role="alert">
{{ session('status') }}
</div>
@endif
<div class="form-group row">
<label for="profile_image" class="col-md-4 col-form-label text-md-right">Profile Image</label>
<div class="col-md-6">
<input id="profile_image" type="file" class="form-control" name="profile_image">
@if (auth()->user()->image)
<code>{{ auth()->user()->profile()->image }}</code>
@endif
</div>
</div>
<div class="form-group row">
<label for="address" class="col-md-4 col-form-label text-md-right">{{ __('Enter First Name:') }}</label> ....
这是我的Profilescontroller,我从其中调用updateprofile();
public function updateProfile(Request $request)
{
// Form validation
$request->validate([
'profile_image' => 'required|image|mimes:jpeg,png,jpg,gif|max:2040',
'address' => 'required',
'phoneno' => 'required',
'sex' => 'required',
'martial_status' => 'required'
]);
// Get current user
$user = User::findOrFail(auth()->user()->id);
// Set user name
$user->accno = $request->input('accno');
//check if a profile image has been uploaded
if ($request->has('profile_image')) {
// Get image file
$image = $request->file('profile_image');
// Make a image name based on user name and current timestamp
$name = Str::slug($request->input('accno')).'_'.time();
// Define folder path
$folder = '/uploads/images/';
// Make a file path where image will be stored [ folder path + file name + file extension]
$filePath = $folder.$name. '.' . $image->getClientOriginalExtension();
// Upload image
$this->uploadOne($image, $folder, 'public' , $name);
// Set user profile image path in database to filePath
$user->profile()->profile_image = $filePath;
}
// Persist user record to database
$user->save();
// Return user back and show a flash message
return redirect()->back()->with(['status' => 'Profile updated successfully.']);
}
请我需要帮助检查我的代码,我用谷歌搜索我的错误,唯一的办法是添加我完成的 crsf 。