Laravel 中没有 table 的模型
Model without table in Laravel
是否可以在 Laravel 中创建与 table 无关的模型?我的意思是模型 Meal
未与 meals
table、Animal
与 animals
table 等相关
我想创建三个模型:Photo
、Reference
、Certificate
并将 Reference
关联到 Photo
并将 Certificate
关联到Photo
作为多态关系。我想要 Reference
和 Certificate
模型只是为了方便,并调用与照片模型有 returns 关系的方法。
传递 Relation
或 Collection
对象作为参数更好吗?哪个更高效、方便?有时我必须使用闭包来
过滤集合,当我们比较它时,它看起来很奇怪
在关系上调用方法链。
在您的模型中使用
protected $table ='your table name';
例如,如果您的 Animal 模型中有大象 table,只需像这样输入此代码
protected $table ='elephant';
是否可以在 Laravel 中创建与 table 无关的模型?我的意思是模型
Meal
未与meals
table、Animal
与animals
table 等相关我想创建三个模型:
Photo
、Reference
、Certificate
并将Reference
关联到Photo
并将Certificate
关联到Photo
作为多态关系。我想要Reference
和Certificate
模型只是为了方便,并调用与照片模型有 returns 关系的方法。传递
Relation
或Collection
对象作为参数更好吗?哪个更高效、方便?有时我必须使用闭包来 过滤集合,当我们比较它时,它看起来很奇怪 在关系上调用方法链。
在您的模型中使用
protected $table ='your table name';
例如,如果您的 Animal 模型中有大象 table,只需像这样输入此代码
protected $table ='elephant';