skip to Main Content

PHP – get closest date from array – Laravel

I want to get closest date from $search_date if is not same values in $array['date']. If is same value in $array['date'] I want all array. Format date is 'Y-m-d'. Example 1: $search_date = '2022-12-08'; $array = [{"price":"200","date":"2022-12-12"},{"price":"50","date":"2022-12-10"},{"price":"100","date":"2022-12-10"}] Return should be:…

VIEW QUESTION

Laravel simplify query method

In Book model I have 2 methods 1 for get book list another for get auth user Favourites book list. Two methods like below For get book list : public function getBooks($id = null) { $query = $this::with("bookImages","author","category")->withCount(['favourites'])->orderBy('created_at', 'desc'); return…

VIEW QUESTION
Back To Top
Search