1

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

enter image description here

What can I do to modify this $email to only get "[email protected]" as my result?

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

1

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);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.