0

So, what I'm trying to obtain is a related model class given an other model class and a column name which is a FK.

Suppose I have a model named 'Event' and a model named 'ShowStatus' and the Event model has 'show_type_id' as foreign key of ShowStatus.

// ...
$model = 'App\Models\Event'; // or an instance of that model
$column = 'show_type_id';

$relatedModel = getRelatedModel($column, $model); // 'App\Models\ShowStatus' should be returned

Is there something in Laravel that can do that?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
didix16
  • 83
  • 1
  • 10
  • is it the answer to your question? `https://stackoverflow.com/questions/26292718/laravel-get-class-name-of-related-model` – Nothehi Oct 05 '20 at 09:03
  • Nope sorry. Thanks for answering anyway :) – didix16 Oct 05 '20 at 10:20
  • Maybe you need [Polymorphic Relationships](https://laravel.com/docs/8.x/eloquent-relationships#polymorphic-relationships)? – mare96 Oct 05 '20 at 11:30
  • @mare96 i'm not looking for that. What I want is to get the related model class by foreign key. thanks anyways :) – didix16 Oct 05 '20 at 11:34

0 Answers0