Laravel get class name of related model
Stefan Bogdanescu
Founder & Senior Architect · 2026-06-29
In Laravel, we often work with models that are connected to each other through various relationships. One of the common relationships is a many-to-many relationship. In such cases, you may need to retrieve the class name for the model involved in these connections. Currently, you can achieve this by running a query using the get() method as shown in the example below:
php
$className = get_class($faq->products()->get()->first());php
$className = $faq->getRelatedQuery()->getModel()->getTable();