app/Http/Controllers/Empresa/UsuarioController.php
/**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
Display a listing of the resource.
@return \Illuminate\Http\Response
Display a listing of the resource . @return \ Illuminate \ Http \ Response
public function index(Request $request)
    {
        $user = User::find(Auth::user()->id);
        if (Auth::user()->hasRole('Administrador')) {
            $usuarios = User::where('empresa_id', $user->empresa_id)->with('roles')->paginate(50);
        } elseif (Auth::user()->hasRole('JefeVentas')) {
            $usuarios = User::where('empresa_id', $user->empresa_id)->where(function ($query) use ($user) {
                $query->orWhere('user_id', $user->id);
                $query->orWhere('id', $user->id);
            })->with('roles')->paginate(50);
        } else {
            $usuarios = User::where('id', $user->id)->with('roles')->get();
        }
        if ($request->is('api/*')) {
            return response()->json(compact('usuarios'));
        }
        return view('usuario.index', compact('usuarios'));
    }
public function index ( Request $ request ) { $ user = User :: find ( Auth :: user ( ) -> id ) ; if ( Auth :: user ( ) -> hasRole ( 'Administrador' ) ) { $ usuarios = User :: where ( 'empresa_id' , $ user -> empresa_id ) -> with ( 'roles' ) -> paginate ( 50 ) ; } elseif ( Auth :: user ( ) -> hasRole ( 'JefeVentas' ) ) { $ usuarios = User :: where ( 'empresa_id' , $ user -> empresa_id ) -> where ( function ( $ query ) use ( $ user ) { $ query -> orWhere ( 'user_id' , $ user -> id ) ; $ query -> orWhere ( 'id' , $ user -> id ) ; } ) -> with ( 'roles' ) -> paginate ( 50 ) ; } else { $ usuarios = User :: where ( 'id' , $ user -> id ) -> with ( 'roles' ) -> get ( ) ; } if ( $ request -> is ( 'api/*' ) ) { return response ( ) -> json ( compact ( 'usuarios' ) ) ; } return view ( 'usuario.index' , compact ( 'usuarios' ) ) ; }
Display a listing of the resource.
Display a listing of the resource .
// $usuarios->push($user); //$usuarios = User::where('empresa_id',Auth::user()->empresa_id)->orderBy('nombre')->paginate(50);