Alaa Mohammad
Alaa Mohammad

Reputation: 665

Get lone value from first result row of a database query with Laravel

I use DB::connection to access another database I got right result

$query = 'select organisation from organisations where id = '.$datum->organisation_id . ' LIMIT 1';

$organisation  = DB::connection('mysql2')->select($query);

and here is the result:

array:1 [▼
  0 => {#2318 ▼
    +"organisation": "XYZ Bank"
  }
]

I don't know how to access the value of the organisation.

Upvotes: 0

Views: 42

Answers (1)

Masoud Haghbin
Masoud Haghbin

Reputation: 883

you can access using

$organisation[0]->organisation

but instead of queries like that you can use Laravel query builder

$organisation  = DB::connection('mysql2')->table('organisations')->where('id',$datum->organisation_id)->select('organisation')->first();

Upvotes: 2

Related Questions