jackade2024 started a new conversation+100 XP
5mos ago
Hi,
I have a problem with multiple tables that share the same structure.
For example, I have several orders tables for each year, such as orders_2020, orders_2021, and so on. These tables are created dynamically every year.
Now, I want to handle all of them through a single model called OrderAll.
I would like to use this model in a way that allows me to access all Eloquent functionalities, such as OrderAll::query()->select()->whereHas()->whereJsonContains()->with(), etc.
Is there any way to implement this approach? I already tried extending Eloquent with custom Builder classes like UnionEloquentBuilder and UnionQueryBuilder, but it doesn’t work correctly with relationships and other functionalities. I keep running into bugs and unhandled errors.
use Illuminate\Database\Query\Builder; use Illuminate\Database\Eloquent\Builder; use Illuminate\Contracts\Pagination\LengthAwarePaginator;
I want this solution to work for both MySQL and PostgreSQL.
I would be very happy and grateful for your help.
Thanks a lot.