/** * @param Request $request * @param $id * @return \Illuminate\Http\JsonResponse */ public function update(Request $request, $id) { $artists = Artist::find($id); if (!$artists) { return response()->json(['status' => 'error', 'message' => 'artista no encontrado']); } try { $this->validate($request, Artist::$rules); $input = $request->all(); $artists->name = $input['name']; $roles = Roles::whereIn('id', $input['rol'])->get(); $artists->save(); $artists->roles()->saveMany($roles); return response()->json(['status' => 'success']); } catch (ValidationException $e) { return response()->json(['status' => 'validation_error', 'messages' => $e->validator->errors()]); } catch (\Exception $e) { return response()->json(['status' => 'server_error', 'message' => $e->getMessage()]); } }
/** * detail of role * @param $id * @return \Illuminate\Http\JsonResponse */ public function detail($id) { $roles = Roles::with('Artist')->find($id); return response()->json($roles); }