I've a relationship between two tables : chapters and modules and here they are :
class Chapter extends Model
{
public function module()
{
return $this->belongsTo(Module::class, 'module_id');
}
}
class Module extends Model
{
protected $primaryKey = 'slug';
public function chapters()
{
return $this->hasMany(Chapter::class, 'module_id');
}
}
But when I use the relationship it always returns nothing :
$module->chapters;
Is there something that I'm missing?