Laravel attach() method not working to hasMany side

前端 未结 4 1488
孤街浪徒
孤街浪徒 2020-12-18 21:34

The application has the models:

Atividade.php

class Atividade extends Eloquent {
    public function interv         


        
4条回答
  •  臣服心动
    2020-12-18 22:26

    attach() is for many-to-many relationships. It seems your relationship is supposed to be a many-to-many but you have not set it up correctly for that.

    class Intervencao extends Eloquent {
        public function atividades() {
            return $this->belongsToMany('Atividade');
        }
    }
    

    Then the attach() should work

提交回复
热议问题