bradcornford / Bootstrapper

An easy way to integrate Twitter Bootstrap with Laravel
MIT License
23 stars 15 forks source link

Bootstrap::date default value format #18

Closed Gzerox closed 10 years ago

Gzerox commented 10 years ago

Hi Again sir, I’m unable to get date format working (while loading a value)

edit.blade.php

Bootstrap::date('date', '', Input::old('date'), $errors, ['class' => 'form-control datepicker'], ['format' => 'DD-MM-YYYY’])

when the edit page has been loaded, on “Date” Field, i’ve:

2014-08-01 00:00:00

on DB this field is a TIMESTAMP, this don’t work event if i try in this way:

date(‘d-m-Y',Input::old('date’))
//01-01-1970

or

date(‘d-m-Y',strtotime(Input::old('date')))
//01-01-1970
Gzerox commented 10 years ago

ATM i’ve found this solution: on Controller->Edit , by default we search for a model and then pass it to the view My model on the view is $match, so in my case:

$match->date->format('d-m-Y’)

the “format” method will only work if on your model you’ve declared which attribute have to be consider as date: model/Match.php

protected $dates = ['date’];

so in my view from TIMESTAMP -> d-m-Y :

Bootstrap::date('date', '', $match->date->format('d-m-Y'), $errors, [], ['format' => 'DD-MM-YYYY’])
bradcornford commented 10 years ago

Hi there,

Yes, by default Laravel can't parse date, and format them using Carbon until being directed as to which model items are dates using the $dates array.

protected $dates = ['date'];

By default Bootstrapper has the ability to automatically set the posted value of any item added to the page upon a form submission, in case validation fails, etc. This way, you only ever have to pass the current set value of the item in question, from either the model, or null.

Is everything now sorted?

Just so you are aware, I have created a base application for Laravel, if you want to get any insights: https://github.com/bradcornford/Laravel-Bootstrap-Base/

Gzerox commented 10 years ago

Thank you brad :+1: