What is the best practice to show old value when editing a form in Laravel?

前端 未结 6 1061
暗喜
暗喜 2021-02-01 03:04

I am writing the logic for an edit form and have some complications when displaying data in the inputs.

When I initially show the form, I show the records values like:

6条回答
  •  醉梦人生
    2021-02-01 03:29

    I solved that issue in my application if you want to get old previous inserted value in input you should try this one I did like this.

    function SaveData(Request $request)
    {
           $sValidationRules = [
            'firstname' => 'required',
            'lastname' => 'required',
            'email' => 'required',
            'phone' => 'required',
          ];
    
          $validator = Validator::make($request->all(), $sValidationRules);
    
          if ($validator->fails()) // on validator found any error 
          {
            // pass validator object in withErrors method & also withInput it should be null by default
             return redirect('Your Route Hare')->withErrors($validator)->withInput();
          }
    
    
          Employee::create($request->all());
    
          return redirect(' your route hare ');
    }
    

    & after then get old data in input field value like this using {{ Request::old('firstname') }} Happy Coding. :)

    
    

提交回复
热议问题