Merhabalar,
Laravel 4.1'de softdelete aktif olduğu modellerde Model::all() komutuyla silinmemiş tüm modelleri alabiliyordunuz.
Laravel 4.2 ile birlikte yine aynı yöntem çalışıyor ama soft delete ile silinen yöntemlerde listeleniyor
Çözüm önerisi olarak birçok yerde şu önerilmiş..
Product::withTrashed()->get()
Ama bu yol eğer model başka bir modeli extends etmişse çalışmıyor.
şu hataları veriyor:
//…/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php346
* Get a global scope registered with the modal.
*
* @param \Illuminate\Database\Eloquent\ScopeInterface $scope
* @return \Illuminate\Database\Eloquent\ScopeInterface|null
*/
public static function getGlobalScope($scope)
{
return array_first(static::$globalScopes[get_called_class()], function($key, $value) use ($scope) // hata satırı: ErrorException Undefined index: Product
{
return $scope instanceof $value;
biraz kurcaladım ve şunu fark ettim; eğer softdelete aktif olduğu model sadece Eloquent miras alınarak oluşturulmuş bir sınıf ise Model::Withtrashed()->get() çalışıyor. Aşağıdaki örnekteki gibi ise ilk bahsettiğim hatayı veriyor.
<?php
use Illuminate\Support\Contracts\MessageProviderInterface;
/**
* Multi Language Model Base
*
* @author Murat Ödünç <murat.asya@gmail.com>
*/
class BaseMultiLang extends Eloquent implements MessageProviderInterface {
}
sorun yaşadığım model:
<?php
use Illuminate\Database\Eloquent\SoftDeletingTrait;
use Cviebrock\EloquentSluggable\SluggableInterface;
use Cviebrock\EloquentSluggable\SluggableTrait;
use MyTool\admin\TraitForModels;
/**
* Description of Product
*
* @author Murat Ödünç <murat.asya@gmail.com>
*/
class Product extends BaseMultiLang implements SluggableInterface {
/*
* A Trait for Slug
*/
use SluggableTrait;
/*
*
*/
use TraitForModels;
/**
* Adding Soft Delete
* It must be on Laravel 4.2 to enabled softDeletes
*/
use SoftDeletingTrait;
protected $dates = ['deleted_at'];
/**
* Model Table Name
* @var string
*/
public $table = 'products';
İşin daha garibi unittest'lerde Product::withTrashed()->get() çağırdığımda sorunsuz çalışıyor. Ama aynı satırlar ne kontrollerda çalışıyor, ne de Product Modelinin içinde çalışıyor.