Freddywhest / firestore-eloquent

This Laravel library provides an Eloquent-like interface for interacting with Firestore, Google Cloud's NoSQL database.
https://firestore-eloquent.netlify.app
MIT License
7 stars 4 forks source link

Cannot retrieve documents from Collections Data #15

Closed enarltd closed 2 months ago

enarltd commented 3 months ago

Describe the bug A clear and concise description of what the bug is. I am trying to get all the documents from a Firestore collection. I am able to get the data and when I dd($results), I see the array of objects returned. But when I try to loop through the data or retrieve them to show in my blade view, I get nothing.

To Reproduce Steps to reproduce the behavior: $cData = Contribution::all(); dd($cData); //this give me the data from the collection

But I don't get anythig when I try this: foreach ($cData as $value) { dd(value); //looks like this does not run at all. }

Expected behavior The loop should run

Freddywhest commented 3 months ago

The documentation states that add ->data() to get the data. Your have to be like

foreach ($cData->data() as $value) {
dd($value); //looks like this does not run at all.
}

Or

$cData = Contribution::all()->data();

enarltd commented 2 months ago

I get this error when I do that...

See screenshot below:

Screenshot 2024-07-04 at 9 29 33 AM
Freddywhest commented 2 months ago

Do you want to count the data or display it?

Freddywhest commented 2 months ago

If you want to do both, here an example:

$cData = Contribution::all();

$count = $cData->count();

$data = $cData->data();

enarltd commented 2 months ago

I want to display it. There is no "count()" in my code. I want to get the documents and display them in my blade view. The "->data()" works when I query using the "first()" or "find()" but when I am getting all(), it gives me that count() error.

enarltd commented 2 months ago

When I do this: $cData = Contribution::all(); $contributionData = $cData->data();

I still get the "count()" error on the 2nd line.

Maybe I am ignorantly doing something wrong somewhere

Freddywhest commented 2 months ago

I'm sure, look through your code

Maybe I am ignorantly doing something wrong somewhere

enarltd commented 2 months ago

I'm sure, look through your code

Maybe I am ignorantly doing something wrong somewhere

Could you help with parts of the code I should check because I don't know where I am starting from though

enarltd commented 2 months ago

When I do dd($cData); I get the screeenshot below:

Screenshot 2024-07-04 at 10 11 32 AM

I can see the documents all under the "-queryRaw" array...

But when I do dd($cData->data()); I get the error again.

Freddywhest commented 2 months ago

The error has been resolved. Please update to the latest version (2.0.1)

Freddywhest commented 2 months ago

I'm sure, look through your code

Maybe I am ignorantly doing something wrong somewhere

Could you help with parts of the code I should check because I don't know where I am starting from though

The error was related to the package, not your code. Sorry about that. Please update to the latest version (2.0.1)

enarltd commented 2 months ago

Thank you Sir I'll revert soon

Freddywhest commented 2 months ago

Thank you Sir I'll revert soon

You're welcome! Please let me know after you have checked, so I can close the issue

enarltd commented 2 months ago

Thank you Sir I'll revert soon

You're welcome! Please let me know after you have checked, so I can close the issue

Working perfectly Sir. Thank you!