vendredi 8 avril 2016

laravel5.1(eloquent) order & extend returned collection

I've got a transaction table using this design:

|id|value|payed_out|...|created_at|updated_at

Now I would like to return all transactions ordered by date and limited to 15 which are:

  • not payed_out (means payed_out == null)
  • not older than 24h (means all transactions which timestamp from now to the timestamp of "created_at" is <24h)

query could look something like:

Transactions::where(payed_out, null)->where(?how to perform the not older check?) ->orderBy('created_at', 'desc') ->take(15)
           ->get();

I would need to "extend" the returned collection of the query I described above.

In my view I would like to display the time until the transaction "expire" means I would need to "add" a field into the collection containing the "time" from the "created_at" field of the transaction until now.

Hope you understand my need.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire