我有这些数据库表:
country_US
country_FR
country_EN
country_NL
country_ES
如何为上述表格创建单个模型?所有这些表的数据库结构都是相同的。
Lumen 框架中这种情况的解决方法是什么?
我不知道数据库设计如此糟糕的原因。理想的情况是只有一个带有“语言”列的表。
无论如何,一种肮脏的方法是覆盖getTable()方法:
/**
* Get the table associated with the model.
*
* @return string
*/
public function getTable()
{
if ($conditionUS)
return 'country_US';
if ($conditionFR)
return 'country_FR';
// etc ...
}
getTable()方法是 Laravel 内部用来确定模型应该使用的表的方法。如果您覆盖它,您将控制将使用哪个表。