mirror of
https://github.com/brunofontes/shareit.git
synced 2025-11-15 07:50:54 -03:00
Added Delete PRODUCT with Items and dettaching from users
This commit is contained in:
15
app/Item.php
15
app/Item.php
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user