Level 13
You have to take the first collection only using first
$x = DB::table('user_profiles')
->where('id',$holidays[0]
->profile_id)
->select('first_name')->first();
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have this query in laravel am trying to use but it's returning an array is there a method to have it an object instead?
$x = DB::table('user_profiles')
->where('id',$holidays[0]
->profile_id)
->select('first_name')->get();
Why don't you use Eloquent for that then?
If you have a UserProfile model, use this:
$profile = UserProfile::findOrFail($holidays[0]->profile_id);
$profile->first_name; // will give you the name
Please or to participate in this conversation.