I'm having an issue updating all records of a relationship modal. Instead only one model is updating all records. I need EACH record to be updated.
I have a MODEL which has holds a "retailer" and this model has an hasMany relationship with a "Location" model. The location model belongsTo the retailer model.
The Location model holds Addresses for retailers. Some Retailers have many locations (addresses). I have tried many solutions but cannot seems to get any to work. The only solution that has worked is using first(); which updates the first record, but I need to update all address records.
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.')
;
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire