如何使用软删除在 Laravel 中一次 restore/forceDelete 多个项目
How to restore/forceDelete multiple item at once time in Laravel using soft delete
当我使用软删除的恢复方法时,效果很好。但我想一次恢复多个项目。可以通过软删除吗?请有任何建议。谢谢。
$products = Product::onlyTrashed()
->whereIn('id', $request->product_ids)
->get();
$products->restore();
显示以下错误信息。
Method Illuminate\Database\Eloquent\Collection::restore does not exist.
很简单。
只需在 eloquent 上使用 restore() 方法而不是集合:
$products = Product::onlyTrashed()
->whereIn('id', $request->product_id)
->restore();
当我使用软删除的恢复方法时,效果很好。但我想一次恢复多个项目。可以通过软删除吗?请有任何建议。谢谢。
$products = Product::onlyTrashed()
->whereIn('id', $request->product_ids)
->get();
$products->restore();
显示以下错误信息。
Method Illuminate\Database\Eloquent\Collection::restore does not exist.
很简单。
只需在 eloquent 上使用 restore() 方法而不是集合:
$products = Product::onlyTrashed()
->whereIn('id', $request->product_id)
->restore();