软删除不能正常工作
问题描述:
我有一个软件删除博客应用程序中的帖子的问题。我不知道为什么在软删除之后,具有非null deleted_at列的记录在检索之后仍然可见。我不知道什么是错的。比如我看到的列表中记录,如:软删除不能正常工作
"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}','[email protected]');
我控制器的方法:
public function deletePost($id){
post::findOrFail($id)->delete();
return redirect()->back()->withSuccess('Post has been deleted corectly.');
}
有人可以帮我解决我的问题吗?我将非常感激,问候。
答
好吧,我知道什么是错的。问题出现在后期模型中的counstructor。删除一个工作正常后。
这是什么laravel版本?顺便说一下:它是'CałkaRiemanna',而不是'CałkaRiemann'。 –
我发现了一些类似的问题,可能有助于您的问题。 http://stackoverflow.com/questions/22426165/laravel-soft-delete-posts和 http://stackoverflow.com/questions/18041155/why-soft-deleted-entities-appear-in-query-results –
Can你向我们展示了你以后如何检索帖子? – Brad