Php Laravel5:';HasManyThrough&x27;使用一个模型和一个中间表而不是两个模型
是否可以将中间表作为Php Laravel5:';HasManyThrough&x27;使用一个模型和一个中间表而不是两个模型,php,laravel,laravel-5,pivot-table,has-many-through,Php,Laravel,Laravel 5,Pivot Table,Has Many Through,是否可以将中间表作为hasManyThrough()的第二个参数传递?我只想用桌子,不是模型。应该是这样的: return $this->hasManyThrough( 'App\Post', 'database.table', <- table instead of model 'country_id', 'user_id', 'id', 'id' ); 返回$this->hasManyThrough( “App\Post”, ‘databa
hasManyThrough()
的第二个参数传递?我只想用桌子,不是模型。应该是这样的:
return $this->hasManyThrough(
'App\Post',
'database.table', <- table instead of model
'country_id',
'user_id',
'id',
'id'
);
返回$this->hasManyThrough(
“App\Post”,
‘database.table’,这是不可能与雄辩的关系联系在一起的
实现所需功能的最简单方法是创建一个新模型,该模型只引用表名:
class Example extends Model
{
protected $table = "database.table";
//or whatever the name of your table is
}
然后,您可以执行以下操作:
return $this->hasManyThrough(
'App\Post',
'App\Example',
'country_id',
'example_id',
'id',
'id'
);
忘了补充一下,您还需要定义示例和PostYep之间的关系,我知道这个方法,但想知道一个没有额外模型的解决方案。无论如何,Thx!