/** * Update the specified resource in storage. * * @param Request $request * @param int $id * @return Response */ public function update(Request $request, Image $image) { $image->update($request->except('_method', '_token', 'artist_list', 'piece_list')); $pieces = count($request->input('piece_list')) ? $request->input('piece_list') : []; $artists = count($request->input('artist_list')) ? $request->input('artist_list') : []; $image->pieces()->sync($pieces); $image->artists()->sync($artists); return redirect()->route('admin.images.show', $image->id)->with('message', 'Image updated'); }