软删除操作无法正常工作

时间:2017-04-23 22:45:23

标签: php database laravel

我在博客应用程序中软删除帖子时遇到问题。我不知道为什么在软删除之后,具有非null deleted_at列的记录在retrievevinig之后仍然可见。我不知道什么是错的。例如,我在列表记录中看到如下:

"id" => 7
"topic" => "Całka Riemann"
"content" => "Ważne pojęcie w analizie matematycznej"
"category_id" => 3
"user_id" => 16
"created_at" => "2017-04-16 17:38:15"
"updated_at" => "2017-04-23 21:49:41"
"deleted_at" => "2017-04-23 21:49:41"

我的帖子模型看起来:

<?php

namespace artSite;

use Illuminate\Database\Eloquent\Model;
use artSite\category;
use Illuminate\Database\Eloquent\SoftDeletes;
class post extends Model
{
    use SoftDeletes;
    protected $table = 'posts';

    protected $fillable = ['topic', 'content', 'category_id','user_id'];
    protected $dates = ['deleted_at'];
    public function __construct() {


    }
    public function category(){

        return $this->belongsTo('artSite\category');

    }
    public function user(){

        return $this->belongsTo('artSite\user');
    }

}

我的路线:

Route::get('dashboard/delete/{id}','adminPanelController@deletePost');

我的控制器方法:

public function deletePost($id){

        post::findOrFail($id)->delete();
        return redirect()->back()->withSuccess('Post has been deleted corectly.');

    }

有人可以帮我解决问题吗?我会非常感激,问候。

1 个答案:

答案 0 :(得分:0)

好的,我知道出了什么问题。问题出在后期模型中的counstructor。删除一个正常工作。