Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel 4.2软删除不起作用_Php_Laravel_Laravel 4_Frameworks - Fatal编程技术网

Php Laravel 4.2软删除不起作用

Php Laravel 4.2软删除不起作用,php,laravel,laravel-4,frameworks,Php,Laravel,Laravel 4,Frameworks,我使用laravel 4.2.8和雄辩的ORM。 当我尝试软删除它不工作。它会从我的数据库中删除数据。 我想从逻辑上而不是物理上删除数据。 在这里,我给出了我的代码,我尝试了什么 型号 use Illuminate\Auth\UserInterface; use Illuminate\Database\Eloquent\SoftDeletingTrait; class User extends Eloquent implements UserInterface { /**

我使用laravel 4.2.8和雄辩的ORM。 当我尝试软删除它不工作。它会从我的数据库中删除数据。 我想从逻辑上而不是物理上删除数据。 在这里,我给出了我的代码,我尝试了什么

型号

use Illuminate\Auth\UserInterface;
use Illuminate\Database\Eloquent\SoftDeletingTrait;

class User extends Eloquent implements UserInterface {

    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'users';
        public $timestamps = true;
        protected $softDelete = true;
        protected $dates = ['deleted_at'];

        public static function boot()
        {
            parent::boot();
            static::creating(function($post)
            {
                $post->created_by = Auth::user()->id;
                $post->updated_by = Auth::user()->id;
            });

            static::updating(function($post)
            {
                $post->updated_by = Auth::user()->id;
            });

            static::deleting(function($post)
            {
                $post->deleted_by = Auth::user()->id;
            });
        }
}
控制器

public function destroy($id) {
        // delete
        $user = User::find($id);
        $user->delete();

        // redirect
        return Redirect::to('admin/user');
    }

从4.2开始,您需要
使用SoftDeletingTrait现在,不设置
受保护的$softDelete=true不再

use Illuminate\Auth\UserInterface;
use Illuminate\Database\Eloquent\SoftDeletingTrait;

class User extends Eloquent implements UserInterface {

    use SoftDeletingTrait;

    protected $table = 'users';
    public $timestamps = true;
    protected $dates = ['deleted_at'];

    public static function boot()
    {
        parent::boot();
        static::creating(function($post)
        {
            $post->created_by = Auth::user()->id;
            $post->updated_by = Auth::user()->id;
        });

        static::updating(function($post)
        {
            $post->updated_by = Auth::user()->id;
        });

        static::deleting(function($post)
        {
            $post->deleted_by = Auth::user()->id;
        });
    }
}

你需要像这样使用特质

use SoftDeletingTrait;
在你开始上课的时候