i'm updating rental belongsto location, , can fill , persist rental data, when fill location relationship data retrieved through eager loading if try save(), update(), or push(); isn't persisted database. according docs push() should work apparently persists relationships.
update action
public function update($id, rentalupdaterequest $request) { // eager load rental relationships $rental = rental::with('location')->find($id); // retrieve rental data request, , fill $requestdata = $request->only('stall', 'level', 'description'); $rental->fill($requestdata); // retrieve rental location data request, , fill $requestdata = $request->only( 'location.street_address', 'location.city', 'location.province', 'location.country', 'location.postal_code' ); $rental->location->fill($requestdata); // persist rental database, relationships $rental->update(); // return rental data capture angularjs interceptor return response()->json([ 'rental' => $rental, 'action' => 'rental_updated', 'message' => trans('rental.updated') ]); } payload , eager loaded data formatted same way
original rental loaded in client
rental: description: "this rental." id: 1 level: "7" location: city: "victoria" country: "canada" id: 11 postal_code: "v8t 2l5" province: "british columbia" street_address: "180 blanshard dr." region_id: 1 rental_location_id: 11 stall: "7" user_id: 1 if payload is:
rental: description: "this rental." id: 1 level: "9" <-- changed location: city: "asdf" <-- changed country: "asdf" <-- changed id: 11 postal_code: "v8t 2l5" province: "asdf" <-- changed street_address: "180 blanshard dr." region_id: 1 rental_location_id: 11 stall: "7" user_id: 1 response after save(), update(), or push()
rental: description: "this rental." id: 1 level: "9" <-- persisted location: city: "victoria" <-- not persisted country: "canada" <-- not persisted id: 11 postal_code: "v8t 2l5" province: "british columbia" <-- not persisted street_address: "180 blanshard dr." region_id: 1 rental_location_id: 11 stall: "7" user_id: 1 appears in laravel 5.1 push() being dropped api, no longer in 5.1 docs, save() , update() don't work either, suggestions?
i've run several times now, try set attributes of eagerly loaded relationship, top level key:value pairs persisted, , child relationship pairs not. way around appears to grab location separately , save(), point of eager loading if can't save relationship, , have make request db.
Comments
Post a Comment