Added Delete PRODUCT with Items and dettaching from users

This commit is contained in:
2018-09-17 00:51:41 -03:00
parent 0edbfa0fdb
commit a2d0bf6c15
4 changed files with 21 additions and 27 deletions

View File

@@ -18,13 +18,14 @@ class Item extends Model
return $this->belongsToMany(User::class);
}
public function free($product_id, $user_id)
public static function deleteAndDetach($item)
{
return $query->where([
['user_id', $user_id],
['product_id', $product_id],
['used_by', ''],
]);
}
//Detach users from this item
foreach ($item->users as $user) {
User::findOrFail($user->id)->items()->detach($item->id);
}
//Delete item
$item->delete();
}
}