简体   繁体   中英

Laravel update form

Hello i'm using laravel and i'm using a specific method for users, seller and another type of user.

So if i'm updating a form of users ( them contain : pseudo, password, if the seller have paid ad another field ) the password was updated if the field is null, and i don't want this and i can't show the password because laravel use bcrypt for hash password and we can only verify if the hash is the same as a password entered as a plain text.

My problem is really specific, i have serch solution but no on have the same problem. Any solution ?

 public function update(Request $request,$id)
{
    $inputs = $request->all();
    dd($inputs);
    $seller = Seller::find($id);
    $seller->pseudo = $inputs['pseudo'];
    $seller->password = Hash::make($inputs['password']);
    $seller->token_related_product = $inputs['token_related_product'];
    $seller->save();
    return view('backend.home');
}

If you only want to set a new passwort if the password field is filled, just compare the value of the field to an empty string. If it's not empty, hash the password and save it to the database, otherwise skip this step.

public function update(Request $request,$id)
{
    $inputs = $request->all();

    $seller = Seller::find($id);
    $seller->pseudo = $inputs['pseudo'];

    if ($request->filled('password')) {
        $seller->password = Hash::make($inputs['password']);
    }

    $seller->token_related_product = $inputs['token_related_product'];
    $seller->save();

    return view('backend.home');
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM