Deep Relations in Laravel: Handling Course-Episode Relationships
In Laravel, you often deal with relationships that span multiple tables. Here's a quick guide to counting related data through deep relations:
Option 1: Using hasManyThrough
When you store a direct reference like course_id
in the episodes
table, you can establish a deep relation using hasManyThrough
. This is perfect for counting through intermediate relationships.
// file: Topic.php