laravelyajra-datatable

Yajra Datatables - Column Date Format


laravel 8 with yajra Datatables. The datatable is created well, but i need to custom some column data.

return [
            Column::computed('action')
                ->exportable(false)
                ->printable(false)
                ->width(60)
                ->addClass('text-center'),
            Column::make('id')
                ->title('ID'),
            Column::make('name')
                ->title('Nome Acabamento'),
            Column::make('enabled')
                ->title('Visível'),
            Column::make('created_at'),
            Column::make('updated_at'),
        ];

In this example i need the created_at to be date format (d-m-Y) and id to be a sum operation from id + 1000.


Solution

  • I got it :

    ->editColumn('created_at', function($data){ $formatedDate = Carbon::createFromFormat('Y-m-d H:i:s', $data->created_at)->format('d-m-Y'); return $formatedDate; })