久久久久久久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.成人久久 | 亚洲美女网站 | 久久狼人天堂 | 日韩欧美二区 | ww亚洲ww亚在线观看 | 天天夜天天操 | 韩日av在线| 高清国产午夜精品久久久久久 | 亚洲视频不卡 | 久久久91精品国产一区二区三区 | 国产在线播放一区二区三区 | 91精品国产自产精品男人的天堂 | 国产ts人妖系列高潮 | avav在线看| 影音先锋中文字幕在线观看 | 久草在线免费资源 | 国产日韩欧美另类 | 四虎永久免费黄色影片 | 日本不卡一区二区三区 | 第一区在线观看免费国语入口 | 久久久免费毛片 | av黄色免费在线观看 | 日韩成人高清在线 | 久久久久久91 | 欧美在线高清 | 九九精品在线 | 欧美成人精品激情在线观看 | 天堂在线中文 | 天堂视频免费 | 一区二区日本 | 美女在线观看av | 欧美亚洲国产精品 | 999精品在线观看 | 欧美亚洲国产日韩 | 亚洲69p| 欧美精品久久 | 国产欧美在线播放 | 成人性视频免费网站 | xxx.在线观看 | 成人h片在线观看 | 狠狠色综合久久丁香婷婷 |