Hello everyone i want to ask about my problem. I want to get which data if column a is b or column b is a for a messaging app. I think you will understand when you see the code. And I also think I did nothing wrong in writing the code. this is my code and the response
Variable for this test
var uid: "QqAIR5Qwd6erFQIgSG"
var friend_uid: "Pk6R56XmWMywcObV3a"
Test 1
Chat::where(['sender'=>$request->uid, 'receiver'=>$request->friend_uid])->get();
Response
"data": [
{
"id": 4,
"sender": "QqAIR5Qwd6erFQIgSG",
"receiver": "Pk6R56XmWMywcObV3a",
"message": "eyJpdiI6Ik8xSld4QlQ3bmMxaWxBMVlua3B0WXc9PSIsInZhbHVlIjoidGMvNGpXVmowVDczRUhSdGM0UkFQNHNjSVVZcFEyeFJlRThWNGdhMWZQMUFodkIwNWJtNmg4cmg1T2NOTm5ZdXBkdzdWWWhUY3hDQUtnVFBGcHllMkE9PSIsIm1hYyI6IjRkYTI5OTk3ZTRhMDAwZTdkYzgwODVmOTgyYzdlYTY2NDg0ZGM2YmExMDVkYzdiMzRhOTliYjA2MjU1ZTc3ZTkiLCJ0YWciOiIifQ==",
"created_at": "2022-03-02T09:29:44.000000Z",
"updated_at": "2022-03-02T09:29:44.000000Z"
}
]
This is valid response
Test 2
Chat::where(['sender'=>$request->friend_uid, 'receiver'=>$request->uid])->get();
Response
"data": []
This is valid because it doesn’t exist in the database, if there is then he will appear I’ve tried it.
Test 3 (i want to do this)
Chat::where(['sender'=>$request->uid, 'receiver'=>$request->friend_uid])->orWhere('sender'=>$request->friend_uid, 'receiver'=>$request->uid)->get();
Response
"data": [
{
"id": 2,
"sender": "30B67S1tV7O7sJRG2l",
"receiver": "QqAIR5Qwd6erFQIgSG",
"message": "eyJpdiI6IkFDaFNMNjZESk96ZU5rSTQyMVhOUEE9PSIsInZhbHVlIjoiaDZyZU9TRSs2c0VTdkVlU2ZDd2JvZHpvQTh3KzZIYjk0NWJrbm90Tk9WREhBV2lrTS9xQW9KOXIza0MwaHUyMGUrTnlBS21aNXBRd1BweXJldlhiOWkzR0hqeHlFWERpdXczZ1E4NTJCSUU9IiwibWFjIjoiMzA3YmQwZmM4NjFlOTk3YmQwNzMwMzgxMTQ4ZmRhZDBhY2IzOWJkZWMzYWVhZmQyNjQ2NGI1MzM4NDQ2ZWY4YiIsInRhZyI6IiJ9",
"created_at": "2022-03-02T09:29:44.000000Z",
"updated_at": "2022-03-02T09:29:44.000000Z"
},
{
"id": 4,
"sender": "QqAIR5Qwd6erFQIgSG",
"receiver": "Pk6R56XmWMywcObV3a",
"message": "eyJpdiI6Ik8xSld4QlQ3bmMxaWxBMVlua3B0WXc9PSIsInZhbHVlIjoidGMvNGpXVmowVDczRUhSdGM0UkFQNHNjSVVZcFEyeFJlRThWNGdhMWZQMUFodkIwNWJtNmg4cmg1T2NOTm5ZdXBkdzdWWWhUY3hDQUtnVFBGcHllMkE9PSIsIm1hYyI6IjRkYTI5OTk3ZTRhMDAwZTdkYzgwODVmOTgyYzdlYTY2NDg0ZGM2YmExMDVkYzdiMzRhOTliYjA2MjU1ZTc3ZTkiLCJ0YWciOiIifQ==",
"created_at": "2022-03-02T09:29:44.000000Z",
"updated_at": "2022-03-02T09:29:44.000000Z"
},
{
"id": 87,
"sender": "chT9eSJ0N6HAXlkUUL",
"receiver": "QqAIR5Qwd6erFQIgSG",
"message": "eyJpdiI6Ikd4ZFZZTE1IVXRGQXNCVmUxUmJhcUE9PSIsInZhbHVlIjoiNWNUZE91Mk41K2o5Si9TSktOdEpNVSswYlVXZDlQd2hyTWY0d256cEJ4YkZKNVg0Y2hwbmNiUTJkZFhMSGxzVSIsIm1hYyI6IjA5ZDk2MDNkYzFhYzY0MTNlNTM3ODNmZDFiZDU3OTc2NThkODg4MGQzZGM5ZWQyYWRjM2Q1YzJmODkwNmUwOTYiLCJ0YWciOiIifQ==",
"created_at": "2022-03-02T09:29:44.000000Z",
"updated_at": "2022-03-02T09:29:44.000000Z"
}
]
why when I try with a query like this I get data which doesn’t match the uid or friend_uid? what happened and if where is the error in my program?, please help, thank you.