I would have added ->whenCounted('notes') in the resource, but the project is with the Laravel version 8 and ->whencounted() wasn't in this previous version.
Aug 16, 2023
5
Level 63
withCount not the same value in local and production
Hello,
I have this code for the backend of an application Laravel / VueJS.
$student = Student::
with('sessions')
...
->withCount(['notes' => function ($query) {
$query->where('show', true);
}])
->find($id);
return new StudentResource($student);
public function toArray($request)
{
return [
'id' => $this->id,
...
'notes_count' => $this->notes_count,
];
}
In local, notes_count equals 0 and in production equals 1.
Sure I have checked and there is in both cases 1 note.
That's the first time that I encounter such a problem with a difference between local an production.
UPDATED => The same query string on phpmyadmin local vs production doesn't give the same result 1 vs 0. So it's a problem with MySQL. But which one ?
Thanks a lot.
V
Level 63
Oh damn ... a simple id problem.
No problem with the database.
Please or to participate in this conversation.