mercredi 2 décembre 2015

How to format a date in Laravel using ::lists

I am coding a feature in Laravel where a user can use a select box to choose a certain date. By standard, these dates are saved in y-m-d in my table.

I have succeeded in formatting the date to dd/mm/yyyy by using the Eloquent solution, adding to my Eloquent Model called Dataslot:

protected $dates = ['maand'];

Afterwards I could use the following to format the date.

     $d = Dataslot::find(1);
     $dformat = $d->maand->format('d-m-Y');

In order to pass the ID of the dataslot and the date to my select box, I have chosen to use the lists method.

$dataslots = Dataslot::lists("maand","id");

This returns me an array. I cannot use the format method on this array as I could on the object in the first example.

How can I have an array of formated dates, with the ID as a key, to send to my view?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire