vendredi 22 avril 2016

Laravel 5.1 - add missing data to response

I have this function to get all max-offers from maxoffers table:

public function maxoffers($id)
    {

        $offers = Maxoffer::where('article_id', $id)->latest()->get(['id', 'price', 'start', 'user_id']);

        return $offers;
    }

and I get this:

[{"id":121,"price":67,"start":"Sat, 23 Apr 2016 00:00:00 +0000","user_id":8},{"id":114,"price":45,"start":"Sun, 08 May 2016 00:00:00 +0000","user_id":9},{"id":113,"price":53,"start":"Sun, 24 Apr 2016 00:00:00 +0000","user_id":8},{"id":111,"price":55,"start":"Wed, 01 Jun 2016 00:00:00 +0000","user_id":11},{"id":110,"price":53,"start":"Fri, 03 Jun 2016 00:00:00 +0000","user_id":8},{"id":107,"price":53,"start":"Wed, 03 Aug 2016 00:00:00 +0000","user_id":8},{"id":106,"price":53,"start":"Mon, 01 Aug 2016 00:00:00 +0000","user_id":8},{"id":105,"price":53,"start":"Tue, 16 Aug 2016 00:00:00 +0000","user_id":8},{"id":104,"price":55,"start":"Thu, 21 Apr 2016 00:00:00 +0000","user_id":11},{"id":101,"price":57,"start":"Wed, 17 Aug 2016 00:00:00 +0000","user_id":8}]

Now i have also:

$start = 'Sun, 03 Apr 2016 00:00:00';
$end = 'Sat, 23 Sep 2016 00:00:01';

How I can go day by day throuth $offers from $start date to $end date and if there is no date for that day to add into $offers new object with data:

{"title":,"price":100,"start":"DATE_WHICH_NOT_EXCIST INTO_OFFERS","user_id":8}

So how I can go throuth $offers and if there is not some date in period from $start to $end then to add new object to json?

So if some date bettween start and end dont excist then add new object... How I can make it possible?

better exaplanation: With $offers I get json with dates but not all dates. So I need to get for all dates between start and end if not alredy exict into offers



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire