我曾尝试在数据透视表中附加自定义列值但是有没有办法在laravel 4.1中分离给出具有自定义列值的where条件?
#User Model
public function pass() {
return $this->belongsToMany('Test')->withPivot('action')->withTimestamps();
}
#Test Model
public function pass() {
return $this->belongsToMany('User')->withPivot('action')->withTimestamps();
}
Attach :
$user->pass()->attach(10, array('action' => 1)); # this works fine
Detach :
$user->pass()->detach(10, array('action' => 1)); # deletes all entries irrespective of action value !
任何想法
答案 0 :(得分:1)
这可能会有效,但可能取决于您的操作是否具有自己的模型:
$user->pass()->newPivotStatementForId($pass->id)->whereActionId($action->id)->delete();
或者也许:
$user->pass()->newPivotStatementForId($pass->id)->whereAction($action_id)->delete();