5

I'm trying to use the soft delete functionality of Elequent ORM in Laravel 4.1

Deleting records works as expected, however when I search for results using withTrashed() and then check to see if it was a soft deleted record using trashed() I get the following error

Call to undefined method Illuminate\Database\Eloquent\Collection::trashed()

Here is my code. Any suggestions?

$product = Product::withTrashed()->where('url', Input::get("product_url.$key"))->where('prolist_id', $list->id)->get();

if($product->trashed())
{
    $product->restore();
}
user1462432
  • 233
  • 3
  • 9

1 Answers1

7

get() is returning a collection of objects. If you only want one result, you can do first() instead and call trashed() on that. If you want several, you'll have to call the method individually for each item in a loop.

Joel Hinz
  • 24,719
  • 6
  • 62
  • 75
  • That makes sense. Think I gotta brush up on the return values of the different methods... Thanks for the reply! – user1462432 May 14 '14 at 20:23