Laravel global scope cannot operate on restricted data after use.

1. I made a global scope for the article model to soft delete data

 public static function boot()
{
    parent::boot();
    static::addGlobalScope("myPost",function(Builder $builder){
        $builder->where("mark_status","<>",-1);
    });
}

2. Then I reported the wrong No query results for model [App\ Post] when I operated on the soft deleted data.

    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" => ""
        ];
    }

do you have any good ways to solve it

Jul.23,2021

I replaced the scope with a soft delete model, and then reported an error No query results for model

when restoring and modifying the soft delete model.

clipboard.png

Menu