Laravel 4 many to many relationship not working, pivot table not found

后端 未结 1 1989
情深已故
情深已故 2021-01-12 22:15

I\'m currently having problems with a n:n relationship with Laravel 4, I\'m having an error wiht pivot table which is quering on a table with with both components on singula

1条回答
  •  执笔经年
    2021-01-12 23:10

    The pivot table should be singular version of the table names it is linking, in alphabetical order so in your case:

    land_obj rather than lands_objs

    If you really don't want to use the default naming conventions you can also specify the table name as the 2nd param on the belongsToMany call in your models:

    return $this->belongsToMany('Obj', 'lands_objs');
    

    and

    return $this->belongsToMany('Land', 'lands_objs');
    

    For more information see docs here

    0 讨论(0)
提交回复
热议问题