<tfoot id='hqFuM'></tfoot>

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

    • <bdo id='hqFuM'></bdo><ul id='hqFuM'></ul>

    <i id='hqFuM'><tr id='hqFuM'><dt id='hqFuM'><q id='hqFuM'><span id='hqFuM'><b id='hqFuM'><form id='hqFuM'><ins id='hqFuM'></ins><ul id='hqFuM'></ul><sub id='hqFuM'></sub></form><legend id='hqFuM'></legend><bdo id='hqFuM'><pre id='hqFuM'><center id='hqFuM'></center></pre></bdo></b><th id='hqFuM'></th></span></q></dt></tr></i><div id='hqFuM'><tfoot id='hqFuM'></tfoot><dl id='hqFuM'><fieldset id='hqFuM'></fieldset></dl></div>
  2. <legend id='hqFuM'><style id='hqFuM'><dir id='hqFuM'><q id='hqFuM'></q></dir></style></legend>
    1. 如何从 Laravel 的数据库中重新加载/刷新模型?

      时间:2023-10-31
      • <bdo id='54G67'></bdo><ul id='54G67'></ul>

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

            • <tfoot id='54G67'></tfoot>
              <legend id='54G67'><style id='54G67'><dir id='54G67'><q id='54G67'></q></dir></style></legend>

                  <tbody id='54G67'></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 的数据库中重新加载/刷新模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:在 Windows 7 中安装 Laravel 4.1//使 .phar 文件对 Windows 命令行全局可用 下一篇:Laravel 会话数据不会跨页面加载

                相关文章

                    • <bdo id='1zjGW'></bdo><ul id='1zjGW'></ul>

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

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