久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在多對多關(guān)系 Laravel 中命名表

naming tables in many to many relationships laravel(在多對多關(guān)系 Laravel 中命名表)
本文介紹了在多對多關(guān)系 Laravel 中命名表的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我擔(dān)心多對多 Laravel 關(guān)系中的自動命名表.

I concerned about auto naming tables in many-to-many Laravel relationship.

例如:

Schema::create('feature_product', function (Blueprint $table) {}

當(dāng)表名改為:

Schema::create('product_feature', function (Blueprint $table) {}

我的關(guān)系有問題.

product_feature 有什么問題?

推薦答案

Laravel 對數(shù)據(jù)透視表的命名約定是用蛇形大小寫的模型名稱按字母順序用下劃線分隔.因此,如果一個模型是 Feature,另一個模型是 Product,那么數(shù)據(jù)透視表將是 feature_product.

Laravel's naming convention for pivot tables is snake_cased model names in alphabetical order separated by an underscore. So, if one model is Feature, and the other model is Product, the pivot table will be feature_product.

您可以隨意使用任何您想要的表名稱(例如 product_feature),但是您需要在關(guān)系中指定數(shù)據(jù)透視表的名稱.這是使用 belongsToMany() 函數(shù)的第二個參數(shù)完成的.

You are free to use any table name you want (such as product_feature), but you will then need to specify the name of the pivot table in the relationship. This is done using the second parameter to the belongsToMany() function.

// in Product model
public function features()
{
    return $this->belongsToMany('AppFeature', 'product_feature');
}

// in Feature model
public function products()
{
    return $this->belongsToMany('AppProduct', 'product_feature');
}

您可以在文檔中閱讀有關(guān)多對多關(guān)系的更多信息.

You can read more about many to many relationships in the docs.

這篇關(guān)于在多對多關(guān)系 Laravel 中命名表的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

add new element in laravel collection object(在 Laravel 集合對象中添加新元素)
Creating an edit modal in Laravel 5(在 Laravel 5 中創(chuàng)建編輯模式)
Laravel 5.5 API resources for collections (standalone data)(用于集合的 Laravel 5.5 API 資源(獨立數(shù)據(jù)))
What is the best practice to create a custom helper function in php Laravel 5?(在 php Laravel 5 中創(chuàng)建自定義輔助函數(shù)的最佳實踐是什么?)
No #39;Access-Control-Allow-Origin#39; header - Laravel(沒有“Access-Control-Allow-Origin標(biāo)頭 - Laravel)
Laravel Passport Route redirects to login page(Laravel Passport Route 重定向到登錄頁面)
主站蜘蛛池模板: 亚洲黄色高清视频 | 国产视频精品区 | 久久九九免费 | 国产二区视频 | 在线亚洲人成电影网站色www | 天天干夜夜操 | 99国产欧美| 亚洲国产精品suv | 中国一级特黄毛片大片 | 日韩在线高清 | 国产一区二区电影网 | 欧美日韩亚洲国产 | 一区二区三区国产精品 | 日韩在线免费视频 | 色吧色综合 | 欧美激情亚洲天堂 | 国产91 在线播放 | 在线观看黄视频 | 国产精品精品视频一区二区三区 | 91精品久久久久久久久久 | 欧美自拍日韩 | 久久1区 | 欧美日韩国产一区二区三区 | 丝袜美腿一区二区三区动态图 | 一区二区三区在线免费观看 | 成人国产精品久久久 | 一区二区精品 | 日韩中文字幕在线不卡 | 激情五月婷婷在线 | 国产精品久久久久久久毛片 | 欧美九九九 | 奇色影视 | 男女羞羞免费视频 | 日本三级全黄三级a | 国产精品国产a级 | 99精品国自产在线 | 欧美一级三级在线观看 | 成人影院免费视频 | 免费久久99精品国产婷婷六月 | 天天操 天天操 | 999国产精品视频免费 |