久久久久久久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 重定向到登錄頁面)
主站蜘蛛池模板: 亚洲一区二区三区四区五区中文 | 精品亚洲一区二区 | 国产在线一区二区三区 | 在线欧美一区 | 久久69精品久久久久久久电影好 | 亚洲欧美一区二区三区情侣bbw | 亚洲va欧美va人人爽午夜 | 久久一区视频 | 特黄色一级毛片 | 国产乱码精品一区二区三区五月婷 | 黄色操视频 | 日韩欧美一区二区在线播放 | 黄色毛片网站在线观看 | 国产高清免费 | 中文字幕国产精品 | 国产自产21区 | 国产午夜久久久 | 亚洲三级在线观看 | 一级亚洲| 亚洲 欧美 另类 综合 偷拍 | 嫩草影院黄| 亚洲欧美aⅴ | 日韩视频一级 | 国产精品久久久久久久久图文区 | 玖玖视频 | 精品亚洲一区二区三区四区五区 | 一区二区三区视频播放 | 日韩在线视频一区 | 国产精品区二区三区日本 | 欧美精品成人 | 久久av一区 | 人成精品| 国产精品久久福利 | 中文字幕成人av | 一区二区三区四区电影视频在线观看 | 网站黄色在线 | 草草在线观看 | 特级黄一级播放 | 在线播放国产视频 | 久草新在线 | 国产精品国产精品国产专区不蜜 |