pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

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

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

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

        Laravel - 數(shù)據(jù)庫、表和列命名約定?

        Laravel - Database, Table and Column Naming Conventions?(Laravel - 數(shù)據(jù)庫、表和列命名約定?)

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

      2. <tfoot id='R5OGS'></tfoot>

        <legend id='R5OGS'><style id='R5OGS'><dir id='R5OGS'><q id='R5OGS'></q></dir></style></legend>
            <tbody id='R5OGS'></tbody>
            <bdo id='R5OGS'></bdo><ul id='R5OGS'></ul>
              <i id='R5OGS'><tr id='R5OGS'><dt id='R5OGS'><q id='R5OGS'><span id='R5OGS'><b id='R5OGS'><form id='R5OGS'><ins id='R5OGS'></ins><ul id='R5OGS'></ul><sub id='R5OGS'></sub></form><legend id='R5OGS'></legend><bdo id='R5OGS'><pre id='R5OGS'><center id='R5OGS'></center></pre></bdo></b><th id='R5OGS'></th></span></q></dt></tr></i><div class="0wwaus0" id='R5OGS'><tfoot id='R5OGS'></tfoot><dl id='R5OGS'><fieldset id='R5OGS'></fieldset></dl></div>

                1. 本文介紹了Laravel - 數(shù)據(jù)庫、表和列命名約定?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在使用 laravel eloquent 數(shù)據(jù)對象來訪問我的數(shù)據(jù),為我的表、列、外鍵/主鍵等命名的最佳方式是什么?

                  I'm using laravel eloquent data objects to access my data, what is the best way to name my tables, columns, foreign/primary keys etc?

                  我發(fā)現(xiàn),有很多命名約定.我只是想知道哪一種最適合 Laravel eloquent 模型.

                  I found, there are lots of naming conventions out there. I'm just wondering which one best suits for laravel eloquent models.

                  我正在考慮以下命名約定:

                  I'm thinking of following naming convention:

                  1. 單一的表名(例如:Post)
                  2. 單列名稱(例如:userId - 帖子表中的用戶 ID)
                  3. 表格名稱中多個單詞的駝峰式大小寫(例如:PostComment、PostReview、PostPhoto)
                  4. 列名稱中多個單詞的駝峰式大小寫(例如:firstName、postCategoryId、postPhotoId)

                  因此,我可以在控制器中使用類似的語法.

                  So with this, I could use similar syntax in the controller.

                  $result = Post::where('postCategoryId', '4')->get();
                  

                  是否有任何推薦的 Laravel 指南?我可以繼續(xù)使用這些命名約定嗎?

                  Are there any recommended Laravel guidelines for this? Can I proceed with these naming conventions?

                  如果有人有更好的建議,我會很高興聽到的.非常感謝!

                  If someone has better suggestions, I will be very happy to hear them.Thanks a lot!

                  推薦答案

                  Laravel 有自己的命名約定.例如,如果您的模型名稱是 User.php,那么 Laravel 期望類 'User' 位于該文件中.User 模型還需要 users 表.但是,您可以通過在模型上定義表屬性來覆蓋此約定,例如

                  Laravel has its own naming convention. For example, if your model name is User.php then Laravel expects class 'User' to be inside that file. It also expects users table for User model. However, you can override this convention by defining a table property on your model like,

                      class User extends Eloquent implements UserInterface, RemindableInterface {
                          protected $table = 'user';
                      }
                  

                  來自 Laravel 官方文檔:

                  From Laravel official documentation:

                  請注意,我們沒有告訴 Eloquent 將哪個表用于我們的 User 模型.類的小寫復數(shù)名稱將用作表名除非明確指定另一個名稱.所以,在這種情況下,Eloquent將假設 User 模型將記錄存儲在 users 表中.你可以指定一個通過在模型上定義 $table 屬性來自定義表

                  Note that we did not tell Eloquent which table to use for our User model. The lower-case, plural name of the class will be used as the table name unless another name is explicitly specified. So, in this case, Eloquent will assume the User model stores records in the users table. You may specify a custom table by defining a $table property on your model

                  如果您將在另一個表中使用用戶表 id 作為外鍵,那么它應該像 user_id 這樣的蛇形大小寫,以便它可以在關系的情況下自動使用.同樣,您可以通過在關系函數(shù)中指定附加參數(shù)來覆蓋此約定.例如,

                  If you will use user table id in another table as a foreign key then, it should be snake-case like user_id so that it can be used automatically in case of relation. Again, you can override this convention by specifying additional arguments in relationship function. For example,

                      class User extends Eloquent implements UserInterface, RemindableInterface {
                          public function post(){
                              return $this->hasMany('Post', 'userId', 'id');
                          }
                      }
                  
                      class Post extends Eloquent{
                          public function user(){
                              return $this->belongsTo('User', 'userId', 'id');
                          }   
                      }
                  

                  Laravel eloquent關系的文檔

                  對于表中的其他列,您可以隨意命名它們.

                  For other columns in table, you can name them as you like.

                  我建議您瀏覽一次文檔.

                  I suggest you to go through documentation once.

                  這篇關于Laravel - 數(shù)據(jù)庫、表和列命名約定?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關文檔推薦

                  Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死鎖異常代碼?)
                  PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滾動游標不起作用)
                  PHP PDO ODBC connection(PHP PDO ODBC 連接)
                  Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔術方法)
                  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ū)動程序)
                    <tfoot id='2Xief'></tfoot>

                    <small id='2Xief'></small><noframes id='2Xief'>

                          <tbody id='2Xief'></tbody>
                        <legend id='2Xief'><style id='2Xief'><dir id='2Xief'><q id='2Xief'></q></dir></style></legend>
                        • <bdo id='2Xief'></bdo><ul id='2Xief'></ul>

                          <i id='2Xief'><tr id='2Xief'><dt id='2Xief'><q id='2Xief'><span id='2Xief'><b id='2Xief'><form id='2Xief'><ins id='2Xief'></ins><ul id='2Xief'></ul><sub id='2Xief'></sub></form><legend id='2Xief'></legend><bdo id='2Xief'><pre id='2Xief'><center id='2Xief'></center></pre></bdo></b><th id='2Xief'></th></span></q></dt></tr></i><div class="mmwys0w" id='2Xief'><tfoot id='2Xief'></tfoot><dl id='2Xief'><fieldset id='2Xief'></fieldset></dl></div>
                          • 主站蜘蛛池模板: 磁力去毛刺机_去毛刺磁力抛光机_磁力光饰机_磁力滚抛机_精密金属零件去毛刺机厂家-冠古科技 | 学习安徽网| 自动记录数据电子台秤,记忆储存重量电子桌称,设定时间记录电子秤-昆山巨天 | 二手回收公司_销毁处理公司_设备回收公司-找回收信息网 | 上海宿田自动化设备有限公司-双面/平面/单面贴标机 | 润滑脂-高温润滑脂-轴承润滑脂-食品级润滑油-索科润滑油脂厂家 | 分光色差仪,测色仪,反透射灯箱,爱色丽分光光度仪,美能达色差仪维修_苏州欣美和仪器有限公司 | 赛默飞Thermo veritiproPCR仪|ProFlex3 x 32PCR系统|Countess3细胞计数仪|371|3111二氧化碳培养箱|Mirco17R|Mirco21R离心机|仟诺生物 | 拼装地板,悬浮地板厂家,悬浮式拼装运动地板-石家庄博超地板科技有限公司 | 北京四合院出租,北京四合院出售,北京平房买卖 - 顺益兴四合院 | 紧急泄压人孔_防爆阻火器_阻火呼吸阀[河北宏泽石化] | 办公室装修_上海办公室设计装修_时尚办公新主张-后街印象 | 电气控制系统集成商-PLC控制柜变频控制柜-非标自动化定制-电气控制柜成套-NIDEC CT变频器-威肯自动化控制 | RO反渗透设备_厂家_价格_河南郑州江宇环保科技有限公司 | 净气型药品柜-试剂柜-无管道净气型通风柜-苏州毕恩思 | 冷油器-冷油器换管改造-连云港灵动列管式冷油器生产厂家 | 踏板力计,制动仪,非接触多功能速度仪,逆反射系数测试仪-创宇 | 冷水机,风冷冷水机,水冷冷水机,螺杆冷水机专业制造商-上海祝松机械有限公司 | 影像测量仪_三坐标测量机_一键式二次元_全自动影像测量仪-广东妙机精密科技股份有限公司 | 抖音短视频运营_企业网站建设_网络推广_全网自媒体营销-东莞市凌天信息科技有限公司 | 光泽度计_测量显微镜_苏州压力仪_苏州扭力板手维修-苏州日升精密仪器有限公司 | 微学堂-电动能源汽车评测_电动车性能分享网 | 宁夏档案密集柜,智能密集柜,电动手摇密集柜-盛隆柜业宁夏档案密集柜厂家 | 无轨电动平车_轨道平车_蓄电池电动平车★尽在新乡百特智能转运设备有限公司 | Eiafans.com_环评爱好者 环评网|环评论坛|环评报告公示网|竣工环保验收公示网|环保验收报告公示网|环保自主验收公示|环评公示网|环保公示网|注册环评工程师|环境影响评价|环评师|规划环评|环评报告|环评考试网|环评论坛 - Powered by Discuz! | 钢格板|镀锌钢格板|热镀锌钢格板|格栅板|钢格板|钢格栅板|热浸锌钢格板|平台钢格板|镀锌钢格栅板|热镀锌钢格栅板|平台钢格栅板|不锈钢钢格栅板 - 专业钢格板厂家 | 沈飞防静电地板__机房地板-深圳市沈飞防静电设备有限公司 | 学习虾-免费的学习资料下载平台 雪花制冰机(实验室雪花制冰机)百科 | TMT观察网_独特视角观察TMT行业| 液压扳手-高品质液压扳手供应商 - 液压扳手, 液压扳手供应商, 德国进口液压拉马 | 杰福伦_磁致伸缩位移传感器_线性位移传感器-意大利GEFRAN杰福伦-河南赉威液压科技有限公司 | 数控走心机-走心机价格-双主轴走心机-宝宇百科 | 正压送风机-多叶送风口-板式排烟口-德州志诺通风设备 | 精准猎取科技资讯,高效阅读科技新闻_科技猎 | 长沙中央空调维修,中央空调清洗维保,空气能热水工程,价格,公司就找维小保-湖南维小保环保科技有限公司 | 不锈钢螺丝 - 六角螺丝厂家 - 不锈钢紧固件 - 万千紧固件--紧固件一站式采购 | 无痕胶_可移胶_无痕双面胶带_可移无痕胶厂家-东莞凯峰 | 防火板_饰面耐火板价格、厂家_品牌认准格林雅 | 低噪声电流前置放大器-SR570电流前置放大器-深圳市嘉士达精密仪器有限公司 | 六维力传感器_六分量力传感器_模腔压力传感器-南京数智微传感科技有限公司 | 防水套管厂家_刚性防水套管_柔性防水套管_不锈钢防水套管-郑州中泰管道 |