我想获取数据透视模型的关系照片
print(chunks([1,2,3,4,5,6,7,8,9],3))
#[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
print(chunks([1,2,3,4,5,6,7,8,9,10],3))
#[[1, 2, 3], [4, 5, 6], [7, 8, 9, 10]]
调用Pivot模型的模型就是这样
class WeedHasState extends Pivot
{
protected $table = 'weed_has_state';
protected $fillable =['weed_id','weed_state_id','id'];
public function weed()
{
return $this->belongsTo(Weed::class, 'weed_id');
}
public function state()
{
return $this->belongsTo(WeedState::class);
}
public function photos(){
return $this->hasMany(WeedPhoto::class);
}
}
打电话给class Weed extends BaseModel
{
public function states()
{
return $this->belongsToMany(WeedState::class, 'weed_has_state', 'weed_id', 'weed_state_id')
->using(WeedHasState::class)
->withPivot('weed_id', 'weed_state_id')
->withTimestamps();
}
}
不起作用吗?