im using serverfireteam/panel from https://github.com/serverfireteam/panel.
I have build this controller with a datetime value:
class TransportController extends CrudController{
public function all($entity){
parent::all($entity);
$this->filter = \DataFilter::source(new \App\Transport);
$this->filter->add('datum', 'Datum', 'datetime');
$this->filter->submit('search');
$this->filter->reset('reset');
$this->filter->build();
$this->grid = \DataGrid::source($this->filter);
$this->grid->add('nummer', 'Nummer');
$this->grid->add('datum', 'datum');
$this->grid->add('spediteur_id',"Spediteur Id");
$this->grid->add('fahrer_id',"Fahrer Id");
$this->grid->add('fahrzeug_id',"Fahrzeug Id");
$this->grid->add('transportkosten',"Transportkosten");
$this->addStylesToGrid();
return $this->returnView();
}
...
}
I like to format the datetime value (like $this->grid->add('datum', 'datum')->format('d.m.Y');) but I couldn't find the function to format it.
In Laravel you will use Carbon to format dates (and more)
Add this at the top of your controller:
use Carbon\Carbon;
And then you can use it so:
$date = Carbon\Carbon::createFromFormat('d/m/Y', '11/06/1990');
With carbon you can do several things as for example:
Carbon::now()->year
Read the documentation it will be very useful: