阅读(4196) (6)

Laravel 8 更新记录

2021-07-09 14:25:11 更新

要更新可搜索的模型,只需要更新模型实例的属性并将模型 save 到数据库。Scout 会自动将更新同步到你的搜索索引中:

$order = AppModelsOrder::find(1);

// 更新订单...

$order->save(); 

你也可以在 Eloquent 查询语句上使用 searchable 方法来更新一个模型的集合。如果这个模型不存在你检索的索引里,就会被创建:

//  通过 Eloquent 查询更新...
AppModelsOrder::where('price', '>', 100)->searchable();

// 你也可以通过数据间的关联进行更新...
$user->orders()->searchable();

// 你也可以通过数据集合进行更新...
$orders->searchable();