如何在 Laravel 5 的模型中放置复合键? [英] How I can put composite keys in models in Laravel 5?

查看:15
本文介绍了如何在 Laravel 5 的模型中放置复合键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据库中有一个带有两个主键(id 和 language_id)的表,我需要将它放入我的模型中.模型中的默认主键(Laravel 5 中的 Model.php)是 id,我希望主键是 id 和 id_language.我尝试将它与数组或带有 ',' 的字符串放在一起,但它不起作用.它说我无法在字符串中转换数组.

I have in my DataBase a table with two primary keys (id and language_id) and I need put it in my models. The default primaryKey in Models (Model.php in Laravel 5) is id, and I want that the primaryKeys will be id and id_language. I tried put it with arrays or a String with ',' but it doesn't work. It says me that the array could not be converted in String.

推荐答案

你不能.Eloquent 不支持复合主键.

You can't. Eloquent doesn't support composite primary keys.

这是一个 Github 上的问题.

这篇关于如何在 Laravel 5 的模型中放置复合键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆