Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

OmarMakled's avatar

how to achieve that relations with eloquent ?

let's say we have tables

permits
    #   type
    ---------
    1   one
    2   two
    3   three

metas
    permit_id   datable_id  datable_key
    ------------------------------------------------------------
    1           1           car     
    2           1           driver
    3           1           company

cars
    #   model
    ------------------
    1   ford
drivers
    #   name
    ----------------
    1   alex
companies
    #   name
    -----------------
    1   Apple

i don't wanna create table like below cuz there are many fields and not all permits have the same data also there are a lot of permits and sure don't create table for each one

#   type    car_id  driver_id   company_id
---------------------------------------------------------------
1   one     1       null        null
2   two     null        1       null
3   three   null        null        1
0 likes
1 reply
OmarMakled's avatar
OmarMakled
OP
Best Answer
Level 2

for anyone who might face the same issue that called

Polymorphic Many To Many Relation Table Structure more on laravel doc

Please or to participate in this conversation.