Привет! Есть несколько таблиц с полиморфными связями:
topic:
-id
-name
article:
-id
-name
-published_at
book:
-id
-name
-published_at
topic_content
-id
-id_topic
-content_type
-content_type
class Topic extends Model{
public $morphedByMany = [
'articles' => [Article::class, 'name' => 'content', 'table' => 'topic_content'],
'books' => [Book::class, 'name' => 'content', 'table' => 'topic_content'],
];
public $hasMany = [
'content' => [TopicContent::class, 'table' => 'topic_content', 'key' => 'id_topic']
];
}
class Book extends Model{
public $morphToMany = [
'topics' => [Topic::class, 'name' => 'content', 'table' => 'topic_content']
];
}
class Article extends Model{
public $morphToMany = [
'topics' => [Topic::class, 'name' => 'content', 'table' => 'topic_content']
];
}
Как в контроллере Topic вывести весь контент (book и article) c полями name отсортированный по полю published_at в одной таблице?