I needed to change the name of the table based on my query (my tables will have a prefix based on my query). I extended the Model class to MyModel and then redefined the construct method, combining the table name based on my query and the default table name provided by my models.
class MyModel extends Model { public function __construct(array $attributes = []) { parent::__construct($attributes); $this->setTable(Config::get('tablePrefix').$this->getTable()); } }
which you should replace with the configuration table prefix for your approach.
and then in my models I just extended MyModel and everything was fine, including static calls, as I tested.
class Category extends MyModel { protected $table = "categories"; }
Therefore, when my query changed, I changed the configuration I provided and was able to get different table names, such as a__categories, b__categories, and everything was in order, including static calls, relationships and saving to the database.
source share