samedi 28 avril 2018

How to keep previously inserted data if I send blank data while updating through UpdateOrCreate method of Laravel Eloquent?

I am new in Laravel. I am using the UpdateOrCreate method of Laravel and I am trying to update some fields of the form and other fields will be as like as earlier. Let, I have three fields in the form which are user_bio, user_image, user_cover_image. I want to update uer_bio only. I tried various way but I failed. I need to update will fields together! How can I solve this issue?

Here are my codes: profile.blade.php (front-end view):

<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]);



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire