2

I have

{
   "_id": ObjectId("557a9fd73b308828060025f0"),
   "account": {
     "email": "[email protected]" 
  }
   "Phone": {
     "pri": {
         "number": "123456789",
         "type": "02"
     },
    "add": {
         "number": "456456456",
         "type": "03"
     }
  }
}

I use

$user = Sender::where('account.email', '=', '[email protected]')->first();  // WORKING

But I want search number : 123456789 in array Phone->pri

$user = Sender::where('Phone.pri.number', '=', '123456789')->first();  // NOT WORKING => RETURN EMPTY ARRAY

Please help me! Thanks!

4
  • did you try $user = Sender::where('Phone.pri.number', '=', '123456789')->first();? Commented Jun 19, 2015 at 5:52
  • Sorry, this not working! Result return empty [] Commented Jun 19, 2015 at 5:54
  • Instead of first try get() Commented Jun 19, 2015 at 6:07
  • @yogesh: tks but empty result Commented Jun 19, 2015 at 6:10

2 Answers 2

1

try like this

$user = Sender::where('Phone.pri.number', '=', '123456789')->first();
Sign up to request clarification or add additional context in comments.

Comments

0

Try this

$user = Sender::where('Phone.pri.number', '=', 123456789)->first();

Search will consider the data type of search needle. If it is an integer you must not enclose it in ''

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.