Reputation: 366
I have a retrieve statement that goes like this
$arrayAID = request('agentID');
$sizeAID = count($arrayAID);
$aidList = "null";
for($a = 0; $a < $sizeAID; $a++){
$email = DB::table('insuranceAgents')
->select('email')
->where('agentID', '=', $arrayAID[$a])
->get();
dd($email);
}
which returns the result
What can I do to modify this $email to only get "[email protected]" as my result?
Upvotes: 1
Views: 1049
Reputation: 163748
You can use the value()
method:
DB::table('insuranceAgents')->where('agentID', $arrayAID[$a])->value('email');
value('email')
is a shortcut for ->first()->email
You may extract a single value from a record using the
value
method. This method will return the value of the column directly
https://laravel.com/docs/5.5/queries#retrieving-results
Upvotes: 2
Reputation: 6115
You can use ->first()
. In your case,
$arrayAID = request('agentID');
$sizeAID = count($arrayAID);
$aidList = "null";
for($a = 0; $a < $sizeAID; $a++){
$email = DB::table('insuranceAgents')
->select('email')
->where('agentID', '=', $arrayAID[$a])
->get()->first();
dd($email);
}
Upvotes: 1