Answer the question
In order to leave comments, you need to log in
Is it normal for a Model::all() query to return Soft deleted models as well?
The documentation says that Soft Deleted models are automatically excluded from any selections.
public function index()
{
return Category::all();
}
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Category extends Model
{
use SoftDeletes;
protected $dates = ['deleted_at'];
public static function boot() {
static::deleting(function(Category $category) {
//$subcategories = $category->subcategories;
//foreach ($subcategories as $subcategory) $subcategory->delete();
});
}
}
Answer the question
In order to leave comments, you need to log in
By asking a lot of questions, I managed to see the code that the author wrote. From the code, it became clear that he overridden the method in the model boot
, but forgot to call the parent method boot
.
In general, redefining boot for model events is bad practice. Read the documentation for good practice.
So you are doing something very wrong.
The code from the documentation says nothing about your code.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question