雄辩属于关系

时间:2017-01-21 14:41:55

标签: php laravel eloquent

不确定为什么它现在适合我。

我有两张桌子

events
- id

selections
- id
- event_id

从我的Event模型我想要关系选择

class Event extends Model
{
   ...
   public function selections()
   {
        return $this->belongsTo(Selection::class, 'event_id', 'id');
   }
}

我的问题是$event->selections关系不起作用。继续获得null

1 个答案:

答案 0 :(得分:2)

使用数据库架构,它改为hasMany关系。

public function selections()
   {
        return $this->hasMany(Selection::class, 'event_id', 'id');
   }

请参阅文档中的One to many relationship

相关问题