这个问题是这样的:**laravel uuid not showing in query* 然而,这个问题的区别在于,表是一个带有id
字段的透视表,在插入时使用通过MySQL触发器生成的UUID。
我不想为这个数据透视表创建另一个模型,以提供类似问题答案的解决方案。那么,有没有办法从另一个与之相关的模型中执行数据透视表的类型转换?
这个问题是这样的:**laravel uuid not showing in query* 然而,这个问题的区别在于,表是一个带有id
字段的透视表,在插入时使用通过MySQL触发器生成的UUID。
我不想为这个数据透视表创建另一个模型,以提供类似问题答案的解决方案。那么,有没有办法从另一个与之相关的模型中执行数据透视表的类型转换?
3条答案
按热度按时间qoefvg9y1#
我想这可能是你想要的:
在定义了BelongsToMany关系的模型中,添加以下属性:
字符串
更新
我想我们可以在这里使用
php7.0
中的匿名类,而不是为pivot创建一个模型类:型
一般来说,我更喜欢为数据透视表创建模型,或者简单地使用pivot class
xwbd5t1u2#
它对我有效:
个字符
brtdzjyr3#
从Laravel 9开始,你可以将trait
HasUuids
传递给新的示例:字符串
另一种方法是创建一个pivot类并在那里设置这个use语句。然而,这一点被提问者排除在外。