php - use eloquent (or similar) on a json file
I wanna use laravel eloquent to filter json array Is there a way to convert json array to object that eloquent could be work on it?
actually I want to use paginate and group by
piece of my json file:
[{
"Fact_Num": "1210",
"Fact_Date": "1399\/01\/12",
"Fact_Ghabel_Pardakht": 625000,
"Fact_Kala_ID": "151049",
"Fact_Tedad": 1,
"Fact_Price_Joze": 130000,
"Fact_Price_Kol": 130000
},
{
"Fact_Num": "1210",
"Fact_Date": "1399\/01\/12",
"Fact_Ghabel_Pardakht": 625000,
"Fact_Kala_ID": "6260074000144",
"Fact_Tedad": 3,
"Fact_Price_Joze": 65000,
"Fact_Price_Kol": 195000
},
{
"Fact_Num": "1210",
"Fact_Date": "1399\/01\/12",
"Fact_Ghabel_Pardakht": 625000,
"Fact_Kala_ID": "6260098401149",
"Fact_Tedad": 1,
"Fact_Price_Joze": 15000,
"Fact_Price_Kol": 15000
},
{
"Fact_Num": "1210",
"Fact_Date": "1399\/01\/12",
"Fact_Ghabel_Pardakht": 625000,
"Fact_Kala_ID": "111042",
"Fact_Tedad": 0.1,
"Fact_Price_Joze": 1000000,
"Fact_Price_Kol": 100000
}
]
Answer
Solution:
Checkout this package: https://github.com/calebporzio/sushi
It makes eloquent work on arrays.
However, if you only want to group and paginate, you can group with laravels collections (https://laravel.com/docs/8.x/collections) and use the laravel paginator to paginate (https://laravel.com/docs/8.x/pagination#manually-creating-a-paginator).
Source