• <tfoot id='QmwVr'></tfoot>
      <bdo id='QmwVr'></bdo><ul id='QmwVr'></ul>

    1. <small id='QmwVr'></small><noframes id='QmwVr'>

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

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

        如何从 Laravel 中的数据库重新加载/刷新模型?

        时间:2023-09-24
        <i id='Ds9Wg'><tr id='Ds9Wg'><dt id='Ds9Wg'><q id='Ds9Wg'><span id='Ds9Wg'><b id='Ds9Wg'><form id='Ds9Wg'><ins id='Ds9Wg'></ins><ul id='Ds9Wg'></ul><sub id='Ds9Wg'></sub></form><legend id='Ds9Wg'></legend><bdo id='Ds9Wg'><pre id='Ds9Wg'><center id='Ds9Wg'></center></pre></bdo></b><th id='Ds9Wg'></th></span></q></dt></tr></i><div id='Ds9Wg'><tfoot id='Ds9Wg'></tfoot><dl id='Ds9Wg'><fieldset id='Ds9Wg'></fieldset></dl></div>

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

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

                  <tbody id='Ds9Wg'></tbody>

                • 本文介绍了如何从 Laravel 中的数据库重新加载/刷新模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  在我的一些测试中,我创建了一个用户模型,并运行了一些需要保存某些属性的方法.在 Rails 中,我通常会调用诸如 user.reload 之类的东西,它会重新填充数据库中的属性.

                  In some of my tests, I have a user model I have created and I run some methods that need to save certain attributes. In rails, I would typically call something like user.reload which would repopulate the attributes from the database.

                  laravel 有没有办法做到这一点?我通读了 api 并找不到它的方法:http://laravel.com/api/4.1/Illuminate/Database/Eloquent/Model.html 任何关于正确"方法的想法?

                  Is there a way in laravel to do that? I read through the api and couldn't find a method for it: http://laravel.com/api/4.1/Illuminate/Database/Eloquent/Model.html Any ideas on the "right" way to do this?

                  推荐答案

                  我也看不到.看起来你必须:

                  I can't see it either. Looks like you'll have to:

                  $model = $model->find($model->id);
                  

                  您也可以自己创建一个:

                  You can also create one yourself:

                  public function reload()
                  {
                      $instance = new static;
                  
                      $instance = $instance->newQuery()->find($this->{$this->primaryKey});
                  
                      $this->attributes = $instance->attributes;
                  
                      $this->original = $instance->original;
                  }
                  

                  刚刚在这里测试了它,它看起来有效,但不确定这能走多远,Eloquen 是一个相当大的类.

                  Just tested it here and it looks it works, not sure how far this goes, though, Eloquen is a pretty big class.

                  这篇关于如何从 Laravel 中的数据库重新加载/刷新模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Laravel hasMany 关系统计帖子的点赞数和评论数 下一篇:在 Laravel 中使用 Eloquent 检索关系的关系

                  相关文章

                  最新文章

                      • <bdo id='C1GRE'></bdo><ul id='C1GRE'></ul>
                    1. <small id='C1GRE'></small><noframes id='C1GRE'>

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

                    3. <tfoot id='C1GRE'></tfoot>