Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5.1 detach with where

Tags:

laravel-5.1

I want detach without some records

my role_user table is id | role_id | user_id

<?php

   $user->roles()->detach();
?>

I don't want detach all records some records need (I mean find solution to where clause inside detach() ). How can I do this? Thank you.

like image 582
SarangaR Avatar asked Nov 28 '22 07:11

SarangaR


1 Answers

Finnaly I found the solution

$user->roles()->wherePivot('role_id', '!=', 3)->detach();
like image 117
SarangaR Avatar answered Dec 04 '22 05:12

SarangaR