<tfoot id='i5OkX'></tfoot>
      <bdo id='i5OkX'></bdo><ul id='i5OkX'></ul>

      1. <i id='i5OkX'><tr id='i5OkX'><dt id='i5OkX'><q id='i5OkX'><span id='i5OkX'><b id='i5OkX'><form id='i5OkX'><ins id='i5OkX'></ins><ul id='i5OkX'></ul><sub id='i5OkX'></sub></form><legend id='i5OkX'></legend><bdo id='i5OkX'><pre id='i5OkX'><center id='i5OkX'></center></pre></bdo></b><th id='i5OkX'></th></span></q></dt></tr></i><div id='i5OkX'><tfoot id='i5OkX'></tfoot><dl id='i5OkX'><fieldset id='i5OkX'></fieldset></dl></div>

      2. <legend id='i5OkX'><style id='i5OkX'><dir id='i5OkX'><q id='i5OkX'></q></dir></style></legend>

        <small id='i5OkX'></small><noframes id='i5OkX'>

        laravel 的 updateOrCreate 方法

        时间:2023-09-24
        <legend id='D0zu5'><style id='D0zu5'><dir id='D0zu5'><q id='D0zu5'></q></dir></style></legend>

        <tfoot id='D0zu5'></tfoot>

        <small id='D0zu5'></small><noframes id='D0zu5'>

            • <i id='D0zu5'><tr id='D0zu5'><dt id='D0zu5'><q id='D0zu5'><span id='D0zu5'><b id='D0zu5'><form id='D0zu5'><ins id='D0zu5'></ins><ul id='D0zu5'></ul><sub id='D0zu5'></sub></form><legend id='D0zu5'></legend><bdo id='D0zu5'><pre id='D0zu5'><center id='D0zu5'></center></pre></bdo></b><th id='D0zu5'></th></span></q></dt></tr></i><div id='D0zu5'><tfoot id='D0zu5'></tfoot><dl id='D0zu5'><fieldset id='D0zu5'></fieldset></dl></div>
                <tbody id='D0zu5'></tbody>
                • <bdo id='D0zu5'></bdo><ul id='D0zu5'></ul>
                  本文介绍了laravel 的 updateOrCreate 方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我的方法中有以下代码,我通过ajax发送到控制器方法:

                  I have the following code in my method which I am sending via ajax to the controller method :

                      $newUser = AppUserInfo::updateOrCreate([
                          'user_id'   => Auth::user()->id,
                          'about'     => $request->get('about'),
                          'sec_email' => $request->get('sec_email'),
                          'gender'    => $request->get("gender"),
                          'country'   => $request->get('country'),
                          'dob'       => $request->get('dob'),
                          'address'   => $request->get('address'),
                          'mobile'    => $request->get('cell_no')
                      ]);
                  

                  dd($request->all()) 给了我:

                  array:8 [
                    "_token" => "fHeEPfTvgMD3FpIBmmc6DmKXFaiuWKZEiOhg6twQ"
                    "about" => "Some about me."
                    "sec_email" => "example@gmail.com"
                    "country" => "Priority highest"
                    "gender" => "male"
                    "dob" => "12/12/1990"
                    "address" => "Some address"
                    "cell_no" => "234234234"
                  ]
                  

                  这是完美的.

                  Jquery 代码:

                  $('#submit-editProfile-form').on('click', function() {
                      var profileEditForm = $("#edit-user-profile");
                      var formData = $('#edit-user-profile').serialize();
                      profileEditForm.on('submit', function(e){
                          e.preventDefault();
                          $.ajaxSetup({
                              headers: {
                                  'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                              }
                          });
                          $.ajax({
                              url:'/freelance/edit-userProfile-info',
                              type:'POST',
                              data:formData,
                              error: function (data) {
                                 console.log('Error');
                              }
                          });
                      }).submit();
                  });
                  

                  现在的问题是我的表中有一条记录,但上面的代码创建了另一个记录,第二个是它在每次单击按钮(请求)时创建乘以两条记录.

                  推荐答案

                  在您的用例中,您应该指定第二个参数.第一个表示匹配的条件,第二个用于指定要更新的字段.

                  In your use case, you should specify a second parameter. The first indicates the conditions for a match and second is used to specify which fields to update.

                  $newUser = AppUserInfo::updateOrCreate([
                      //Add unique field combo to match here
                      //For example, perhaps you only want one entry per user:
                      'user_id'   => Auth::user()->id,
                  ],[
                      'about'     => $request->get('about'),
                      'sec_email' => $request->get('sec_email'),
                      'gender'    => $request->get("gender"),
                      'country'   => $request->get('country'),
                      'dob'       => $request->get('dob'),
                      'address'   => $request->get('address'),
                      'mobile'    => $request->get('cell_no')
                  ]);
                  

                  以下是文档中的示例:https://laravel.com/docs/5.4/eloquent

                  // If there's a flight from Oakland to San Diego, set the price to $99.
                  // If no matching model exists, create one.
                  $flight = AppFlight::updateOrCreate(
                      ['departure' => 'Oakland', 'destination' => 'San Diego'],
                      ['price' => 99]
                  );
                  

                  这篇关于laravel 的 updateOrCreate 方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Laravel 4:不存在的地方 下一篇:按 created_at 对 Eloquent Collection 进行排序

                  相关文章

                  最新文章

                    <i id='wwwdI'><tr id='wwwdI'><dt id='wwwdI'><q id='wwwdI'><span id='wwwdI'><b id='wwwdI'><form id='wwwdI'><ins id='wwwdI'></ins><ul id='wwwdI'></ul><sub id='wwwdI'></sub></form><legend id='wwwdI'></legend><bdo id='wwwdI'><pre id='wwwdI'><center id='wwwdI'></center></pre></bdo></b><th id='wwwdI'></th></span></q></dt></tr></i><div id='wwwdI'><tfoot id='wwwdI'></tfoot><dl id='wwwdI'><fieldset id='wwwdI'></fieldset></dl></div>
                    <tfoot id='wwwdI'></tfoot>
                        <bdo id='wwwdI'></bdo><ul id='wwwdI'></ul>

                      <small id='wwwdI'></small><noframes id='wwwdI'>

                    1. <legend id='wwwdI'><style id='wwwdI'><dir id='wwwdI'><q id='wwwdI'></q></dir></style></legend>