0

I have tried to make some query in laravel, sometimes work, but sometime not work, the problem is, result of query i made, its not same with actual value on table database, i have no idea to fix that, and iam have a trying to searching this problem in google or stackoverflow, but cannot find issue like that, can anyone tell me about what this problem.

Query SQL

SELECT id, parent_id, status, name FROM works WHERE (status != 'CANCELED' AND deleted_at IS NULL) AND (parent_id = 20 AND type = 'TASK')

image result of sql query

Query Laravel

DB::select("SELECT id, parent_id, status, name FROM works WHERE (status != 'CANCELED' AND deleted_at IS NULL) AND (parent_id = 20 AND type = 'TASK')")

image result of dd in laravel

result of end data with id 66 its cannot founded in table, so iam realy confused, in table iam search data with id 66 its not found, but in result query of laravel made the data its show.

i feel like watching horor movie .

  • simply your laravel is connecting to a different database – Your Common Sense Aug 01 '22 at 10:39
  • how i can now this connect yo another db, iam using 1 db in env config – ikhbalfuady Aug 01 '22 at 11:44
  • **and another db** in phpmyadmin config – Your Common Sense Aug 01 '22 at 11:50
  • i mean, how i can know i got wrong select db in laravel , when i changing some data in query, the data is up to date, but th focus my question is, why i got the latest data , and the id of latest data always changed every i made query, i try to find with that id in table, thats data not found, you can see and compare my screenshoot attachment above – ikhbalfuady Aug 01 '22 at 12:00

1 Answers1

-1

if u have Work model..try this

$works = Work::where('status','!=','CANCELLED')->whereNull('deleted_at')->where('parent_id',20)->where('type','TASK')->get(['id', 'parent_id', 'status', 'name']);

  • "try"? what for? How it's different? – Your Common Sense Aug 01 '22 at 10:49
  • the result its including append too and call relation table when iam using eloquent, why iam using DB::select , because ia want to make fast query process, this query executed 1-100x in once proces in parent method, imagize.. i have 10 query in append & relation , 1 data x 10 = 10, when query run in 5 data, the real query is 50, when method called 10x query execute 500x, that make server hang, so i chose this way, but this anoying bugs make me crazy – ikhbalfuady Aug 01 '22 at 11:51
  • can you show me the whole collection with all colums....?? – Abhilash Sharma Aug 01 '22 at 16:44