コード例 #1
0
 public function users_by_state()
 {
     $states = State::with('users')->get();
     $data = [];
     foreach ($states as $state) {
         $data[] = ['label' => $state->name, 'value' => $state->users->count()];
     }
     return response()->json($data);
 }
コード例 #2
0
 public function delete($id)
 {
     $state = State::findOrFail($this->decode($id));
     if ($state->users->count() > 0) {
         alert(trans('messages.state.not_deleted'), 'danger');
         return redirect()->back();
     }
     $state->delete();
     alert(trans('messages.state.deleted'));
     return redirect()->back();
 }
コード例 #3
0
 public function profile_update(ProfileRequest $request)
 {
     // Comprobar si el email existe solo si se ha cambiado el email
     if ($request->email != auth()->user()->email) {
         $user = User::whereEmail($request->email)->get();
         if (!empty($user)) {
             alert('El email ingresado ya existe', 'danger');
             return redirect()->back();
         }
     }
     $state = State::findOrFail($request->state);
     $user = auth()->user();
     $user->state()->associate($state);
     $user->update($request->all());
     alert('Se modificaron los datos con éxito');
     return redirect()->back();
 }
コード例 #4
0
 public function update($hash_id, UserRequest $request)
 {
     $id = $this->decode($hash_id);
     $form = collect_clean($request->all());
     $usuario = User::findOrFail($id);
     $usuario->update($form->toArray());
     // actualizando departamento
     if ($request->has('state')) {
         if ($request->state != $usuario->state_id) {
             $state = State::findOrFail($request->state);
             $usuario->state()->associate($state);
             $usuario->save();
         }
     }
     alert('Se modificó el usuario correctamente');
     return redirect()->route('admin::usuarios::create');
 }
コード例 #5
0
 public function showRegister()
 {
     $states = State::lists('name', 'id')->toArray();
     return view('register')->with('states', $states);
 }