Skip to content
Advertisement

Laravel: Optional Date filter not working when receiving string from JS frontend

New to Laravel and PHP so having a diffucult time with a small problem:

I’m stepping deep into a Collection and want to bring back nested items only that meet a certain (optional) date criteria.

Unfortunately, it isn’t working (at all). Here is my code:

JavaScript

While I have your attention, how can I only return the analytics_orders array shown below (right now the data is very messy):

enter image description here

Advertisement

Answer

I guess you have mixed laravel collection with eloquent collection. Eloquent collection is on top of laravel collection not vice versa.

In laravel collection, when you use when() method, a that collection will be passed to the closure function, there isn’t anything about laravel eloquent and $query object. You have that collection instance and you should return something in your closure function.

So, edit your closure function as below and use return

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement