1、我对文章模型做了个全局scope用来软删除数据
public static function boot() { parent::boot(); static::addGlobalScope('myPost',function(Builder $builder){ $builder->where('mark_status','<>',-1); }); }
2、然后我在对这些软删除的数据进行操作的时候就报错了No query results for model [App\Post].
public function status(Post $post) { $this->validate(request(),[ 'status' => 'required|in:-1,0,1' ]); $post->mark_status = request('status'); $post->save(); return [ 'error' => 0, 'msg' => '' ]; }
大家有什么好的办法解决吗
慕标5832272
相关分类