Level 70
Try this for getting the full name with namespace.
$className = get_class($user->child()->getRelated());
Try this for getting the base name-
$baseClass = class_basename($className);
11 likes
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have a model App\Models\User in which I define a relationship child with model App\Models\User. Meaning another user can be a child of given user.
Now I want to retrieve the value of model-name refered to by relationship child. Answer: App\Models\User
how to do that in Laravel?
Try this for getting the full name with namespace.
$className = get_class($user->child()->getRelated());
Try this for getting the base name-
$baseClass = class_basename($className);
Please or to participate in this conversation.