Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is Laravel trashed() method not found>

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();
}
like image 821
user1462432 Avatar asked May 14 '14 18:05

user1462432


1 Answers

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.

like image 70
Joel Hinz Avatar answered Sep 28 '22 12:09

Joel Hinz