Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

351
Vistas
Laravel - Method Illuminate\\Support\\Collection::makeHidden does not exist

I want to hide the columns password & OTP ,that is included in $uses result. Actually these 2 columns are part of the users table. I've tried like below. But it generates the error - Method Illuminate\\Support\\Collection::makeHidden does not exist . How to solve this? Any suggestions..

$users = DB::table('users')
            ->join('location', 'users.id', '=', 'location.id')
            ->join('user_technical_details', 'users.id', '=', 'user_technical_details.id')
            ->get();
$d=$users->makeHidden(['password','OTP']);    
return response()->json([
            'message' => 'profile viewed successfully',
            'data' => $d,
            'statusCode' => 200,
            'status' => 'success'],200);  
over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

You're trying to execute this method on the collection but it's a model method:

$users = DB::table('users')
            ->join('location', 'users.id', '=', 'location.id')
            ->join('user_technical_details', 'users.id', '=', 'user_technical_details.id')
            ->get();
foreach($users as $user) {
    $user->makeHidden(['password','OTP']);
}

And this still doesn't work since you're using DB::table('users') over Users::all().


In order to use a model, you have to do the following:

model:

class User extends Model
{
    // Instead of `makeHidden()` you can do this if you want them always to be hidden
    // protected $hidden = ['password','OTP'];

    public function location()
    {
        return $this->hasOne(App\Models\Location::class, 'users.id', '=', 'location.id');
    }

    public function technical_details()
    {
        return $this->hasOne(App\Models\UserTechnicalDetail::class, 'users.id', '=', 'user_technical_details.id');
    }
}

controller:

$users = Users::with(['location', 'technical_details'])
            ->get();
foreach($users as $user) {
    $user->makeHidden(['password','OTP']);
}
over 4 years ago · Santiago Trujillo Denunciar

0

Simplest solution for your case:

$users = DB::table('users')
        ->join('location', 'users.id', '=', 'location.id')
        ->join('user_technical_details', 'users.id', '=', 'user_technical_details.id')
        ->get()
        ->map(function ($user) {
            unset($user->password);
            unset($user->OTP);
            reurn $user;
        });

I'd recommend to use Eloquent Relationships instead of joins for better abstraction:

https://laravel.com/docs/8.x/eloquent-relationships

over 4 years ago · Santiago Trujillo Denunciar

0

In order to get User object from db, you should use User Model:

$users = User::query()
            ->join('location', 'users.id', '=', 'location.id')
            ->join('user_technical_details', 'users.id', '=', 'user_technical_details.id')
            ->get();
foreach($users as $user) {
    $user->makeHidden(['password','OTP']);
}
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda