Laravel: Take the value of an array without foreach

Asked

Viewed 400 times

-1

I have the following appointment:

$TenantId = DB::select('select tenant_id from users where id = :id', ['id' => '7']);

dd($TenantId);

The result of $Tenantid is:

array:1 [▼
  0 => {#357 ▼
    +"tenant_id": 7
  }
]

I need the result to be: 7

How do I display only number 7? The reason is because I need this 'tenant_id' to use in the next query which is:

$subdomain = DB::select('select subdomain from tenants where id = :id', ['id' => $TenantId]);

But if I use this way above displays the error:

Array to string Conversion (SQL: select subdomain from tenants Where id = :id)

I have tried to take the value of the following forms, but it has not solved:

$Tenantid['tenant_id'];

or

$Tenantid[0]['tenant_id'];

or

Extract($Tenantid);

*All 3 forms failed.

1 answer

0


From what I could see the correct would be to use $Tenantid[0]->tenant_id

  • Thanks friend... Clarified the doubt... Really this way it worked, I learned one more, thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.