app/Http/Controllers/Empresa/UsuarioController.php
/**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function update(Request $request, $id)
    {
        $usuario = User::find($id);
        $usuario->update($request->except(['foto', 'password']));
        if ($request->has('foto')) {
            $usuario->foto = $request->file('foto')->store('public/usuarios');
            $usuario->save();
        }
        if ($request->has('password') && $request->get('password') != null) {
            $usuario->password = bcrypt($request->get('password'));
            $usuario->save();
        }
        if ($request->has('role')) {
            $usuario->syncRoles($request->get('role'));
        }
        if (Auth::user()->id == $id) {
            $usuario->primer_login = 0;
            $usuario->save();
        }
        if ($request->is('api/*')) {
            $vendedores = User::where('empresa_id', auth('api')->user()->empresa_id)->with(['roles'])->orderBy('nombre')->get();
            return response()->json(compact('vendedores', 'exito'));
        }
        if (Auth::user()->hasRole('SuperAdministrador')) {
            return redirect('empresa/' . $usuario->empresa_id);
        }
        return redirect('e/usuario');
    }
public function update ( Request $ request , $ id ) { $ usuario = User :: find ( $ id ) ; $ usuario -> update ( $ request -> except ( [ 'foto' , 'password' ] ) ) ; if ( $ request -> has ( 'foto' ) ) { $ usuario -> foto = $ request -> file ( 'foto' ) -> store ( 'public/usuarios' ) ; $ usuario -> save ( ) ; } if ( $ request -> has ( 'password' ) && $ request -> get ( 'password' ) != null ) { $ usuario -> password = bcrypt ( $ request -> get ( 'password' ) ) ; $ usuario -> save ( ) ; } if ( $ request -> has ( 'role' ) ) { $ usuario -> syncRoles ( $ request -> get ( 'role' ) ) ; } if ( Auth :: user ( ) -> id == $ id ) { $ usuario -> primer_login = 0 ; $ usuario -> save ( ) ; } if ( $ request -> is ( 'api/*' ) ) { $ vendedores = User :: where ( 'empresa_id' , auth ( 'api' ) -> user ( ) -> empresa_id ) -> with ( [ 'roles' ] ) -> orderBy ( 'nombre' ) -> get ( ) ; return response ( ) -> json ( compact ( 'vendedores' , 'exito' ) ) ; } if ( Auth :: user ( ) -> hasRole ( 'SuperAdministrador' ) ) { return redirect ( 'empresa/' . $ usuario -> empresa_id ) ; } return redirect ( 'e/usuario' ) ; }
Update the specified resource in storage.
Update the specified resource in storage .