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

  • <legend id='dlLbY'><style id='dlLbY'><dir id='dlLbY'><q id='dlLbY'></q></dir></style></legend>

      <tfoot id='dlLbY'></tfoot>
      <i id='dlLbY'><tr id='dlLbY'><dt id='dlLbY'><q id='dlLbY'><span id='dlLbY'><b id='dlLbY'><form id='dlLbY'><ins id='dlLbY'></ins><ul id='dlLbY'></ul><sub id='dlLbY'></sub></form><legend id='dlLbY'></legend><bdo id='dlLbY'><pre id='dlLbY'><center id='dlLbY'></center></pre></bdo></b><th id='dlLbY'></th></span></q></dt></tr></i><div id='dlLbY'><tfoot id='dlLbY'></tfoot><dl id='dlLbY'><fieldset id='dlLbY'></fieldset></dl></div>
          <bdo id='dlLbY'></bdo><ul id='dlLbY'></ul>
      1. Laravel Eloquent::Find() 使用现有 ID 返回 NULL

        时间:2023-09-24
          <tbody id='QnZON'></tbody>
      2. <small id='QnZON'></small><noframes id='QnZON'>

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

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

                  <bdo id='QnZON'></bdo><ul id='QnZON'></ul>

                  本文介绍了Laravel Eloquent::Find() 使用现有 ID 返回 NULL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  它非常简单,因为它是最基本的东西,但我不知道我错过了什么:

                  It's pretty straightforward as it's the most basic thing but I don't know what I'm missing:

                  有一个名为 Site

                  我正在使用 Eloquent ORM,所以当我调用(在控制器中)

                  I'm using Eloquent ORM, so when I call (in a controller)

                  $oSite = Site::find(1)
                  

                  然后

                  var_dump($oSite);
                  

                  它返回一个 NULL 的值.

                  但是当我检查数据库时,表sites"实际上包含以下项目:

                  But when I check the database, the table 'sites' actually contains the following item:

                  id: 1
                  user_id: 1
                  name: test
                  

                  在我的 Site model 中,我有以下代码:

                  In my Site model I have the following code:

                  use IlluminateDatabaseEloquentModelNotFoundException;
                  
                   Class Site extends Eloquent {
                  
                          protected $table = 'sites';
                  
                          protected $fillable = ['user_id', 'name'];
                   }
                  

                  相反,如果我使用以下内容收集项目:

                  Instead, if I gather the item with the following:

                  $oSite = DB::table('sites')
                                  ->where('id', 1)
                                  ->first();
                  

                  它有效并且我得到了正确的寄存器.

                  It works and I get the correct register.

                  我做错了什么?我没有得到文档的哪一部分?

                  What I'm doing wrong? Which part of the documentation I didn't get?

                  型号代码可以在上面查看.

                  Model code can be checked above.

                  控制器:

                  use IlluminateSupportFacadesRedirect;
                  class SiteManagementController extends BaseController {
                  
                  ...
                  
                      public function deleteSite()
                      {
                          if (Request::ajax())
                          {
                              $iSiteToDelete = Input::get('siteId');
                  
                              $oSite = Site::find($iSiteToDelete);
                  
                              return var_dump($oSite);
                          }
                          else
                          {
                              return false;
                          }
                      }
                  }
                  

                  编辑 2:(已解决)

                  不工作的真正原因:

                  我的模型代码原本如下:

                  use IlluminateDatabaseEloquentSoftDeletingTrait;
                  use IlluminateDatabaseEloquentModelNotFoundException;
                  
                  Class Site extends Eloquent {
                  
                      protected $table = 'sites';
                  
                      use SoftDeletingTrait;
                  
                      protected $dates = ['deleted_at'];
                  
                      protected $fillable = ['user_id', 'name'];
                  }
                  

                  问题是我在启动项目后添加了一个deleted_at"列,当我应用迁移时,我没有启用软删除.显然,我犯了第二个错误,忘记启用 'deleted_at' 为可空,因此所有插入的时间戳都错误(0000-00-00 ...).

                  Problem was I added a 'deleted_at' column after I started the project and when I applied migrations, I didn't have softdeleting enabled. Obviously, I did a second error, forgetting to enable 'deleted_at' to be nullable, hence all inserts went had a wrong timestamp (0000-00-00 ...).

                  修复:

                  1. 使deleted_at"列可以为空.

                  将所有错误的 'deleted_at' 时间戳设置为 NULL.

                  Set all wrong 'deleted_at' timestamps to NULL.

                  推荐答案

                  检查您是否正确获取了 Input::get('siteId').如果您得到它,请尝试将其转换为整数,即

                  Check you are getting Input::get('siteId') correctly. if you are getting it then try to convert it into integer i.e

                  $iSiteToDelete = intval(Input::get('siteId'));
                  

                  这篇关于Laravel Eloquent::Find() 使用现有 ID 返回 NULL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:在 Views laravel 上使用 carbon 下一篇:Laravel:在使用查询生成器或 Eloquent ORM 时在每次插

                  相关文章

                  最新文章

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

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

                      <legend id='glxUw'><style id='glxUw'><dir id='glxUw'><q id='glxUw'></q></dir></style></legend>