here is my code and its working fine.
SubjectReport::selectRaw('YEAR(date) as year, MONTH(date) as month')->distinct()->get();
I want to know is it another way to get data from database using eloquent or collection methods?
example:
2023-01
2023-02
2023-03
Thanks.
If you need to get the data in the desired format right at the database level, I think your approach is the way to do it.
An alternative is using mutators to get the right format (but casting is only applied when converting to array or JSON).