Laravel 8 更新记录
2021-07-26 09:58 更新
要更新可搜索的模型,只需要更新模型实例的属性并将模型 save 到数据库。Scout 会自动将更新同步到你的搜索索引中:
$order = App\Models\Order::find(1);
// 更新订单...
$order->save(); 你也可以在 Eloquent 查询语句上使用 searchable 方法来更新一个模型的集合。如果这个模型不存在你检索的索引里,就会被创建:
// 通过 Eloquent 查询更新...
App\Models\Order::where('price', '>', 100)->searchable();
// 你也可以通过数据间的关联进行更新...
$user->orders()->searchable();
// 你也可以通过数据集合进行更新...
$orders->searchable(); 以上内容是否对您有帮助:

免费 AI IDE


更多建议: