1

I used laravel's query builder.

$email=DB::table('users')->where('id',1)->select('e_mail')->get();
dd($email);

and, this is result.

Collection {#231 ▼
  #items: array:1 [▼
    0 => {#229 ▼
      +"e_mail": "[email protected]"
    }
  ]
}

but test code's result was False.

$email=DB::table('users')->where('id',1)->select('e_mail')->get();
"[email protected]"!=$email[0]

I found other questions, but didn't find solution.
please your advise. thanks.

1
  • use ->first(); instead of ->get(); and compare $email['e_mail'] != "[email protected]" /// or if you use get() you need to use $email[0]['e_mail'] != "[email protected]" Commented Nov 20, 2017 at 6:53

3 Answers 3

1

From your output, it seems instead of $email[0], you need to use $email[0]['e_mail'], if it's an array, or you need to use $email[0]->e_mail, if it's an object.

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

Comments

1

Please use it like this:

$email=DB::table('users')->where('id',1)->select('e_mail')->get();

"[email protected]"!=$email[0]->e_mail

Comments

0

you are finding using id.. so i assume it is unique.. if using get() it will return as array.

use Eloquent..

$user = Users::select('e_mail')->find(1);
// $user = Users::select('e_mail')->where('id', 1)->first(); //this also can

if("[email protected]" != $user->email) 
{
    //
}

or Query..use first();

$user=DB::table('users')->where('id',1)->select('e_mail')->first(); 

if("[email protected]" != $user->e_mail) 
{
    //
}

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.