1
我遇到更新關係模式的所有記錄的問題。相反,只有一個模型正在更新所有記錄。我需要每條記錄進行更新。更新關係問題
我有一個擁有「零售商」的模型,該模型與「位置」模型具有hasMany
關係。位置模型屬於的零售商模式。
位置模型包含零售商的地址。一些零售商有許多地點(地址)。我已經嘗試了許多解決方案,但似乎無法得到任何工作。唯一有效的解決方案是使用first();
更新第一條記錄,但我需要更新所有地址記錄。我真的把我的頭髮撕了,我一直堅持4天。我真的準備好自殺了。任何幫助。請。
public function update(Request $request, $id)
{
$location = $request->only(
'street_number',
'street_address',
'city',
'state',
'postcode',
'country',
'longitude',
'latitude',
'country_code'
);
$insert = Location::where('id', $id);
$insert->update($location);
return Redirect::route('retailers.edit', $id)
->withInput()
->withErrors($validation)
->with('message', 'There were validation errors.')
;
}
您需要更新「所有」地址(位置)記錄? – lagbox