距问题日期一年后,使用 Laravel 6,选择的答案还不够。
需要2个步骤来解决这个问题:
1- 正如@Yuvraj 所说,更改Laravel\Telescope\Storage\EntryModel 中的扩展模型:
//use Illuminate\Database\Eloquent\Model;
use Moloquent as Model;
class EntryModel extends Model
2- 在同一类中是一个函数,通过请求中发送的选项来限定查询范围:
public function scopeWithTelescopeOptions($query, $type, EntryQueryOptions $options)
{
$this->whereType($query, $type)
->whereBatchId($query, $options)
->whereTag($query, $options)
->whereFamilyHash($query, $options)
->whereBeforeSequence($query, $options)
->filter($query, $options);
return $query;
}
filter 函数检查记录是否将属性 should_display_on_index 设置为 true,该属性在迁移中设置为默认值:
$table->boolean('should_display_on_index')->default(true);
但是由于使用了 mongoDB,因此不尊重默认参数,因此不会将其添加到记录中。
要解决此问题,您有两种选择:
a) 注释掉前面提到的函数中对过滤器的调用:
public function scopeWithTelescopeOptions($query, $type, EntryQueryOptions $options)
{
$this->whereType($query, $type)
->whereBatchId($query, $options)
->whereTag($query, $options)
->whereFamilyHash($query, $options)
->whereBeforeSequence($query, $options)
/*->filter($query, $options)*/;
return $query;
}
但是,如果您打算稍后通过将 should_display_on_index 设置为 false 来使用过滤器,则需要修改过滤器函数:
protected function filter($query, EntryQueryOptions $options)
{
if ($options->familyHash || $options->tag || $options->batchId) {
return $this;
}
// $query->where('should_display_on_index', true);
$query->where('should_display_on_index', '!=', false);
return $this;
}