It seems like there might be an issue with how the objectID is being determined when the delete operation is being called. The objectID should match the one that was used when the object was indexed. In Laravel Scout, the objectID is typically the primary key of the model unless you've customized the getScoutKey method.
Here's what you can do to troubleshoot and potentially fix the issue:
- Ensure that the
getScoutKeymethod on yourThreadmodel is returning the correct key. If you haven't defined this method, Scout will use the primary key of the model by default.
/**
* Get the value used to index the model.
*
* @return mixed
*/
public function getScoutKey()
{
return $this->getKey();
}
- If you have overridden the
getScoutKeyNamemethod, make sure it is returning the correct key name, which should be the primary key column name.
/**
* Get the key name used by Scout to index the model.
*
* @return string
*/
public function getScoutKeyName()
{
return $this->getKeyName();
}
-
Check if there are any global scopes or local scopes applied to the
Threadmodel that might be altering the ID when the model is being deleted. -
If you are using model events (like
creating,updating,deleting, etc.), ensure that none of these events are modifying the ID in a way that could cause this issue. -
If you have any accessors or mutators on the
Threadmodel that modify the ID, ensure they are not being called in a way that affects the deletion process. -
Finally, if none of the above steps resolve the issue, you can try to manually set the
objectIDbefore deleting the model to ensure it matches the ID used when the model was indexed:
$thread->scoutMetadata(['objectID' => $thread->getScoutKey()]);
$thread->delete();
If after trying these steps the issue persists, it might be helpful to look into the Scout source code or reach out to the Scout community for further assistance. There might be a bug or a specific configuration issue that's causing the objectID to be altered during deletion.