Laravel 中没有 table 的模型

Model without table in Laravel

  1. 是否可以在 Laravel 中创建与 table 无关的模型?我的意思是模型 Meal 未与 meals table、Animalanimals table 等相关

    我想创建三个模型:PhotoReferenceCertificate 并将 Reference 关联到 Photo 并将 Certificate 关联到Photo 作为多态关系。我想要 ReferenceCertificate 模型只是为了方便,并调用与照片模型有 returns 关系的方法。

  2. 传递 RelationCollection 对象作为参数更好吗?哪个更高效、方便?有时我必须使用闭包来 过滤集合,当我们比较它时,它看起来很奇怪 在关系上调用方法链。

在您的模型中使用

protected $table ='your table name';

例如,如果您的 Animal 模型中有大象 table,只需像这样输入此代码

protected $table ='elephant';