Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

353
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!