Search code examples
laraveleloquentrelationshiplaravel-7

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


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 !


Solution

  • 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