没有找到基表或视图:很多对很多关系laravel

时间:2017-05-21 14:22:36

标签: php mysql laravel laravel-5.4 laravel-blade

我有几个模型与枢轴表climbincludeds_tour建立多对多关系:

Tour.php

class Tour extends Model
{
  protected $table = 'tours';
  public function climbIncluded(){
    return $this->belongsToMany('App\ClimbIncluded',
                                'climbincludeds_tour',
                                'tour_id', 'cincluded_id');
    }
}

ClimbIncluded.php

class ClimbIncluded extends Model
{
  protected $table = 'climbincludeds';
    public function tours()
    {
     return $this->belongsToMany('App\Tour');
    }
}

我在ClimbIncludedController.php

中附加了destroy方法的视图上有一个删除按钮
    public function destroy(ClimbIncluded $climbIncluded)
{
    $climbIncluded->tours()->detach();
    $climbIncluded ->delete();
    Session::flash('success','Item sucessfully deleted !');
    return redirect()->route('climb.ie');
}

当我想删除记录时,laravel会返回错误:

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'peak.tour_trek_included' 
doesn't exist (SQL: delete from `tour_trek_included` where `trek_included_id` = 1)

如果我从destroy方法中删除或注释掉$climbIncluded->tours()->detach();,laravel会删除记录而不会出现任何错误。我已经将pivot表的名称作为belongsToMany方法的第二个参数传递给了。我在这里缺少什么?

0 个答案:

没有答案