Я новичок в Ларавеле. Я использую UpdateOrCreate
метод Laravel и пытаюсь обновить некоторые поля формы, а другие поля будут такими же, как и ранее. Пусть у меня есть три поля в форме: user_bio
, user_image
, user_cover_image
. Я хочу обновить только uesr_bio
. Я пробовал по-разному, но мне не удалось. Мне нужно обновить поля воли вместе! Как я могу решить эту проблему?
Вот мои коды:
profile.blade.php (внешний вид):
<div class="card">
<div class="card-header"> প্রোফাইল </div>
<div class="card-body">
<form action="profile/store" method="post" enctype="multipart/form-data">
@csrf
<div class="form-group">
<label for="user_bio">Bio:</label>
<input type="text" class="form-control" id="user_bio" name="user_bio">
</div>
<div class="form-group">
<label>Upload your profile picture:</label>
<input type="file" class="form-control" name="profilepicture" id="profilepicture">
</div>
<div class="form-group">
<label>Upload your cover photo:</label>
<input type="file" class="form-control" name="coverphoto" id="coverphoto">
</div>
<button type="submit" class="btn btn-default" name="submit" value="submit">Submit</button>
</form>
</div>
</div>
ProfileController:
/** User Profile Picture (with URL) Storing Process Starts here **/
$image = $request->file('profilepicture');
$imagenewname= rand() .'.'. $image-> getClientOriginalExtension();
$path = $request->file('profilepicture')->storeAs(
'public/UserImages', $imagenewname
);
$imageName = "UserImages/".$imagenewname;
/** User Profile Picture (with URL) Storing Process Ends here **/
/** User Cover Photo (with path) Storing Process Starts here **/
$coverphoto = $request->file('coverphoto');
$coverphotoname= rand() .'.'. $coverphoto-> getClientOriginalExtension();
$coverphotopath = $request->file('coverphoto')->storeAs(
'public/CoverPhotos', $coverphotoname
);
$coverPhotoName = "CoverPhotos/".$coverphotoname;
/** User Cover Photo (with path) Storing Process Ends here **/
$check = Profile::updateOrCreate(['user_id' => $request->user_id], ['user_bio' => $request->user_bio, 'user_image' => $imageName, 'user_cover_image' => $coverPhotoName]);