【发布时间】:2015-06-17 18:32:39
【问题描述】:
我有以下模型和关系:
class Fence extends Model {
public function fenceLines(){
return $this->hasMany('App\Models\FenceLine');
}
public function newPivot(Model $parent, array $attributes, $table, $exists){
if ($parent instanceof FenceLine) {
return new FenceLine($parent, $attributes, $table, $exists);
}
return parent::newPivot($parent, $attributes, $table, $exists);
}
}
class FencePoint extends Model {
public function fenceLines(){
return $this->hasMany('App\Models\FenceLine');
}
public function newPivot(Model $parent, array $attributes, $table, $exists){
if ($parent instanceof FenceLine) {
return new FenceLine($parent, $attributes, $table, $exists);
}
return parent::newPivot($parent, $attributes, $table, $exists);
}
}
class FenceLine extends Pivot {
protected $table = 'fences_fence_points';
public function fence(){
return $this->belongsTo('App\Models\Fence');
}
public function fencePoint(){
return $this->belongsTo('App\Models\FencePoint');
}
}
当我打电话给$fence->fenceLines() 时,我收到以下错误:
Argument 1 passed to App\Models\Fence::newPivot() must be an
instance of Illuminate\Database\Eloquent\Model, none given
我已经阅读了很多关于这个确切问题的博客,但我找不到任何解决方案。
【问题讨论】:
标签: model laravel-5 pivot-table