久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  • <small id='9Bl1j'></small><noframes id='9Bl1j'>

        <legend id='9Bl1j'><style id='9Bl1j'><dir id='9Bl1j'><q id='9Bl1j'></q></dir></style></legend>
          <bdo id='9Bl1j'></bdo><ul id='9Bl1j'></ul>

        <tfoot id='9Bl1j'></tfoot>
      1. <i id='9Bl1j'><tr id='9Bl1j'><dt id='9Bl1j'><q id='9Bl1j'><span id='9Bl1j'><b id='9Bl1j'><form id='9Bl1j'><ins id='9Bl1j'></ins><ul id='9Bl1j'></ul><sub id='9Bl1j'></sub></form><legend id='9Bl1j'></legend><bdo id='9Bl1j'><pre id='9Bl1j'><center id='9Bl1j'></center></pre></bdo></b><th id='9Bl1j'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='9Bl1j'><tfoot id='9Bl1j'></tfoot><dl id='9Bl1j'><fieldset id='9Bl1j'></fieldset></dl></div>
      2. Laravel 表單模型綁定

        Laravel form model binding(Laravel 表單模型綁定)
        <tfoot id='et3AC'></tfoot>

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

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

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

              <tbody id='et3AC'></tbody>
              • <bdo id='et3AC'></bdo><ul id='et3AC'></ul>
                  本文介紹了Laravel 表單模型綁定的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我一直在閱讀有關(guān)此功能的信息:.真的很有幫助.

                  如果您的表單只有來自單個模型的字段,則您的更新方法可能非常簡單,如下所示:

                  公共函數(shù)更新($id){$user = User::find($id);if (!$user->update(Input::all())) {返回重定向::返回()->with('message', '保存模型時出錯')->withInput();}return Redirect::route('user.saved')->with('message', '用戶更新.');}

                  對于稍微復(fù)雜一點的表單,編碼人員將不得不向他們的控制器添加更多邏輯,如果您進行更多研究,我認為您可以做到這一點:

                  公共函數(shù)更新($id){$user = User::find($id);$inputs = Input::all();如果 (!$user->update($inputs)) {$address = new UserAddress($inputs['address']);$user->address()->save($address);...}...}

                  I've been reading about this feature: http://laravel.com/docs/html#form-model-binding

                  And it looks really neat, but there are couple of things that I'm not certain about.

                  Do I need to put any code in the controller action to process this form? What does that look like?

                  The model (User) I want to bind in my form has a separate table for addresses. So I want to be able to fill out the User model's fields, but also the fields for the related Address model. Can I do that with form-model-binding, or do I have to handle the form manually?

                  Or, failing that, can I use form model binding for the user fields, but manually handle the address fields?

                  解決方案

                  You don't need any different code in your controller to process this form. All your (named) form variables will be in Input::all().

                  The model ($user) you pass in

                  Form::model($user, array('route' => array('user.update', $user->id)))
                  

                  Is just any record you need to, if you have more than one table involved, you'll have to do something like

                  $user = User::where('id',$userID)
                             ->leftJoin('users_addresses', 'users_addresses.user_id', '=', 'users.id')
                             ->first();
                  

                  And pass this composed model to your Form::model().

                  How you name your inputs is entirely up to you, because you'll have to write the logic to process your form. But, in my opinion users_address[street] for the address inputs is good, because you'll end up with an array of addresses columns that you can pass right away to your UserAddress model.

                  <html>
                      <head>
                          <title></title>
                      </head>
                      <body>
                          {{ Form::model($user, array('route' => array('user.update', $user->id))) }}
                              {{ Form::label('first_name', 'First Name:', array('class' => 'address')) }}
                              {{ Form::text('first_name') }}
                  
                              {{ Form::label('last_name', 'Last Name:', array('class' => 'address')) }}
                              {{ Form::text('last_name') }}
                  
                              {{ Form::label('email', 'E-Mail Address', array('class' => 'address')) }}
                              {{ Form::text('email') }}
                  
                              {{ Form::label('address[street1]', 'Address (Street 1)', array('class' => 'address')) }}
                              {{ Form::text('address[street1]') }}
                  
                              {{ Form::label('address[street2]', 'Address (Street 2)', array('class' => 'address')) }}
                              {{ Form::text('address[street2]') }}
                  
                              {{ Form::label('ddress[city]', 'City', array('class' => 'address')) }}
                              {{ Form::text('address[city]') }}
                  
                              {{ Form::label('address[state]', 'State', array('class' => 'address')) }}
                              {{ Form::text('address[state]') }}
                  
                              {{ Form::label('address[zip]', 'Zip Code', array('class' => 'address')) }}
                              {{ Form::text('address[zip]') }}
                  
                              {{ Form::submit('Send this form!') }}
                          {{ Form::close() }}
                      </body>
                  </html>
                  

                  And if you do dd( Input::all() ) in your controller, you'll get something like this:

                  This result is provided by Kint's dd(): https://github.com/raveren/kint. Really helpful.

                  If your form just have fields from a single Model, your update method can be very simple and look something like:

                  public function update($id)
                  {
                      $user = User::find($id);
                  
                      if (!$user->update(Input::all())) {
                          return Redirect::back()
                                  ->with('message', 'Something wrong happened while saving your model')
                                  ->withInput();
                      }
                  
                      return Redirect::route('user.saved')
                                  ->with('message', 'User updated.');
                  }
                  

                  On forms a little bit more complex, coders will have to add more logic to their controllers, in you case with a little bit more of research I think you can make this happen:

                  public function update($id)
                  {
                      $user = User::find($id);
                  
                      $inputs = Input::all();
                  
                      if (!$user->update($inputs)) {
                              $address = new UserAddress($inputs['address']);
                  
                          $user->address()->save($address);
                  
                          ...
                      }
                  
                      ...
                  }
                  

                  這篇關(guān)于Laravel 表單模型綁定的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死鎖異常代碼?)
                  PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滾動游標(biāo)不起作用)
                  PHP PDO ODBC connection(PHP PDO ODBC 連接)
                  Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔術(shù)方法)
                  php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個值;等于變量的值)
                  MSSQL PDO could not find driver(MSSQL PDO 找不到驅(qū)動程序)

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

                    <bdo id='jsaqM'></bdo><ul id='jsaqM'></ul>
                      <legend id='jsaqM'><style id='jsaqM'><dir id='jsaqM'><q id='jsaqM'></q></dir></style></legend>

                        • <tfoot id='jsaqM'></tfoot>

                            <i id='jsaqM'><tr id='jsaqM'><dt id='jsaqM'><q id='jsaqM'><span id='jsaqM'><b id='jsaqM'><form id='jsaqM'><ins id='jsaqM'></ins><ul id='jsaqM'></ul><sub id='jsaqM'></sub></form><legend id='jsaqM'></legend><bdo id='jsaqM'><pre id='jsaqM'><center id='jsaqM'></center></pre></bdo></b><th id='jsaqM'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='jsaqM'><tfoot id='jsaqM'></tfoot><dl id='jsaqM'><fieldset id='jsaqM'></fieldset></dl></div>
                              <tbody id='jsaqM'></tbody>
                            主站蜘蛛池模板: 一区二区在线观看av | 日韩一二三区 | 日韩欧美一区二区三区免费看 | 欧美精品一区二区三区四区五区 | 亚洲毛片在线观看 | 在线不卡视频 | av资源网站 | 精品欧美黑人一区二区三区 | 国产精久久久久久久妇剪断 | 日韩成人国产 | 色综合一区二区三区 | 欧美日产国产成人免费图片 | 久久美女网 | 天堂一区二区三区四区 | 国产精品一区二区三区在线 | 在线观看国产www | 欧美在线观看免费观看视频 | 中文字幕av一区二区三区 | 成人中文字幕在线 | 日韩精品一区二区三区第95 | 成人二区三区 | 天天色官网| 一区二区三区久久 | 在线看无码的免费网站 | 欧美一级片在线看 | 一区二区三区av | 欧美理论片在线观看 | 三级免费av| 亚洲一区二区三区观看 | 国产精品久久久久久久毛片 | 国产成人精品一区二区三区四区 | 亚洲精品av在线 | 欧美成人视屏 | 精品久久99 | 久久综合久久久 | 围产精品久久久久久久 | 国产伦一区二区三区视频 | 久久久久一区 | 日韩欧美在线观看 | 免费在线观看av片 | 亚洲成在线观看 |