Home > Enterprise >  Laravel - How to know which models are related to a specific model?
Laravel - How to know which models are related to a specific model?

Time:09-28

I would like to know the models that are related to my table.

Is there a method to do it like this ?

        $model    = new $model;
        $table    = $model->getTable();
        $columns  = Schema::getColumnListing($table);

For example like this ?

       $model->relationships()

Thank you in advance !

CodePudding user response:

Out of the box there is no way to do it, you have to come up with your own solution. You can try this here: https://laracasts.com/discuss/channels/eloquent/get-all-model-relationships

  • Related