Abdullah Al Mamun
Abdullah Al Mamun

Reputation: 132

How to restore/forceDelete multiple item at once time in Laravel using soft delete

When I use restore method of soft delete it work`s well. But I want to do that multiple item restore at once time. Is it possible by soft delete? Any suggestion please. Thank you.

$products = Product::onlyTrashed()
            ->whereIn('id', $request->product_ids)
            ->get();

$products->restore();

Show the below error message.

Method Illuminate\Database\Eloquent\Collection::restore does not exist.

Upvotes: 1

Views: 1486

Answers (1)

Aleksandar Milivojsa
Aleksandar Milivojsa

Reputation: 385

It is easy.

Just use restore() method on eloquent instead of collection:

$products = Product::onlyTrashed()
    ->whereIn('id', $request->product_id)
    ->restore();

Upvotes: 3

Related Questions