sql无法在laravel控制器中更新

bybem2ql  于 2021-06-19  发布在  Mysql
关注(0)|答案(2)|浏览(299)

我在使用此格式将当前更新的输入保存到数据库时遇到问题。
创建这个数据库是为了通过zapier存储typeform创建的值,但是我想让它可以编辑。
下面是blade.php中的代码片段

<div class="col-md-12 p0 ">
    <div class="col-md-6 PL0 p0_smresp">
        <div class=" form-group "><label for="cilent_email" class="optional">Email</label>
            <input type="text" name="cilent_email" id="cilent_email" value="{{$userProfile->cilent_email }}" class="form-control" autocomplete="off" placeholder="email">
          </div>
      </div>
      <div class="col-md-6 PR0 p0_smresp">
          <div class=" form-group "><label for="client_country" class="optional">Country</label>
           @php $usercountry=explode(" - ",$userProfile->client_country); @endphp
           <select name="client_country" id="client_country" value="{{$usercountry[1]}}" class="form-control " aria-required="true">
               <option value="" selected="selected">{{$usercountry[1]}}</option>
               @foreach ($countries as $country)
                   <option value="{{ $country->id }}" @if( $usercountry[1] == $country->id) selected @endif>{{ $country->country_name }}</option>
               @endforeach
           </select>
       </div>
   </div>
   </div>
   <div class="col-md-12 p0 ">
       <div class=" form-group "><label for="client_accomplishment" class="optional">Accomplishments</label>
           <input type="text" name="client_accomplishment" id="client_accomplishment" value="{{$userProfile->client_accomplishment }}" class="form-control" autocomplete="off" >
       </div>
   </div>
   <div class="col-md-12 p0 ">
       <div class="col-md-6 PL0 p0_smresp">
           <div class=" form-group "><label for="client_firstproj" class="optional">First Project Date</label>
               <input type="date" name="client_firstproj" id="client_firstproj" value="{{$userProfile->client_first_project }}" class="form-control" autocomplete="off">
            </div>
        </div>
        <div class="col-md-6 PR0 p0_smresp">
            <div class=" form-group "><label for="client_totalproj" class="optional">Total Projects Completed</label>
                <input type="text" name="client_totalproj" id="client_totalproj" value="{{$userProfile->client_total_project }}" class="form-control" autocomplete="off">
             </div>
          </div>
      </div>

这是控制器发来的

public function profileSave(Request $request, $id){

     $userProfile= DB::table('user_profile') 
 ->where('cilent_email',Auth::user()->email) 
 ->first();  

    $userProfile->cilent_email = $request->cilent_email; 
    $userProfile->client_country = $request->client_country; 
    $userProfile->client_accomplishments = $request->client_accomplishments; 
    $userProfile->client_first_project = $request->client_firstproj; 
    $userProfile->client_total_project = $request->client_totalproj; 
    $userProfile->enjoy_design = $request->enjoy_design; 
    $userProfile->enjoy_manage = $request->enjoy_manage; 
    $userProfile->enjoy_style = $request->enjoy_style;     

    $user = User::find(Auth::user()->id);
    $user->client_url = $request->client_url;

    // dd($user);
    if($request->skills)
    {
        foreach ($request->skills as  $skill){
            $skills.=$skill.';';
        }
        $userProfile->client_skills = "a:".count($request->skills).":{".$skills."}";
    }
    else{
        $userProfile->client_skills = '';
    }

    $userProfile->save();
    $user->save();
    return redirect()->back()->with('message','Profile Settings Updated');
}

这样,当我提交带有新更新输入的表单时,刷新的页面仍将返回与以前相同的值。

li9yvcax

li9yvcax1#

使用userprofile模型

$userProfile= UserProfile::where('cilent_email',Auth::user()->email)->first();

瞬间 return redirect()->back()->with('message','Profile Settings Updated'); 使用 return redirect(url('your url'));

xdyibdwo

xdyibdwo2#

$id返回旧值$输入包含更新的值。包括 use Illuminate\Support\Facades\Input 为了 Input::all() ```
$input = Input::all();

$id->update($input);

相关问题