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

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

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

        Laravel 4:一个模型可以服务多个数据库表吗?

        时间:2023-09-24
      1. <tfoot id='SLMNa'></tfoot>

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

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

              <i id='SLMNa'><tr id='SLMNa'><dt id='SLMNa'><q id='SLMNa'><span id='SLMNa'><b id='SLMNa'><form id='SLMNa'><ins id='SLMNa'></ins><ul id='SLMNa'></ul><sub id='SLMNa'></sub></form><legend id='SLMNa'></legend><bdo id='SLMNa'><pre id='SLMNa'><center id='SLMNa'></center></pre></bdo></b><th id='SLMNa'></th></span></q></dt></tr></i><div id='SLMNa'><tfoot id='SLMNa'></tfoot><dl id='SLMNa'><fieldset id='SLMNa'></fieldset></dl></div>
                1. 本文介绍了Laravel 4:一个模型可以服务多个数据库表吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  在我的应用程序中,我有几个 mysql 表:Toronto、Vancouver、Montreal 等……我正在使用 DB-class 来处理它们,例如.

                  In my application I have several mysql tables: Toronto, Vancouver, Montreal, etc... and I am using the DB-class to work with them, eg.

                  $data = DB::select('select * from toronto where id = ?', array($id));
                  

                  我想做的是开始使用 Eloquent.我是 Laravel 的新手,只是想知道是否可以将一个模型与多个表一起工作,例如:

                  What I want to do is to start using Eloquent. I am new to Laravel and was just wondering if its possible to have one model work with several tables, smth like:

                  class City extends Eloquent {
                        protected $table_a = 'toronto';
                        protected $table_b = 'vancouver';
                        protected $table_c = 'montreal';
                  }
                  

                  推荐答案

                  它不能,但你可以.有很多方法,这里是一种:

                  It cannot, but you can. There are many ways, here's one:

                  创建一个 City 模型,在其构造函数中要求提供表名:

                  Create your a City model that asks for a table name in its constructor:

                  class City extends Eloquent {
                  
                      public function __construct($city, array $attributes = array())
                      {
                          parent::__construct($attributes);
                  
                          $this->table = $city;
                      }
                  
                  }
                  

                  要使用它,您必须使用表名实例化您的类:

                  To use it you'll have to instantiate your class using the table name:

                  $toronto = new City('toronto');
                  

                  然后你可以用它做任何你想做的事情:

                  Then you can do anything you want with it:

                  var_dump( $toronto->where('id',701057)->get() );
                  

                  这篇关于Laravel 4:一个模型可以服务多个数据库表吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Laravel 在数据透视表中雄辩的 UUID 下一篇:Laravel eloquent 模型模型属性转换(我应该转换哪些

                  相关文章

                  最新文章

                      <bdo id='bh7KQ'></bdo><ul id='bh7KQ'></ul>
                    <legend id='bh7KQ'><style id='bh7KQ'><dir id='bh7KQ'><q id='bh7KQ'></q></dir></style></legend>
                  1. <tfoot id='bh7KQ'></tfoot>

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

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