Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

marcoplus's avatar

Yajra DataTables DataTablesEditor DateTime

Good morning, does anyone know why the date field doesn't work with yajraa? I enter the code

Fields\DateTime::make('year')->format('dd-mm-YYY')  or 
Fields\DateTime::make('year') or 
Fields\Date::make('year')

but the bar and the values ​​disappear. Laravel 10

0 likes
11 replies
marcoplus's avatar

@DhPandya I am using Yajra DataTables DataTablesEditor in my system, now I read in a forum

https://github.com/yajra/laravel-datatables-editor/issues/33
For editor field date for instance, you can already do the format.

Fields\Date::make('start_at')->format('d-m-Y'),
When saving the date, you just need to cast start_at as date and thus no need to format it since Laravel will automatically handle it for us afaik.

that it is possible to use the date field with Yajra DataTables DataTablesEditor, only that when I insert the code the button bar disappears completely, I tried to search but I didn't find it solutions

Fields\Text::make('name'),
Fields\Text::make('description'),
Fields\Text::make('category'),
Fields\Date::make('year')->format('dd-mm-YYY'),

Senza-titolo.png

marcoplus's avatar

@NekaDava Yes, I entered but the result is always the same, where am I going wrong?

protected $casts = [
 'created_at' => 'datetime:d-m-Y H:i:s',
 'updated_at' => 'datetime:d-m-Y H:i:s',
 'year' => 'datetime:d-m-Y H:i:s',
 ];
NekaDava's avatar

@marcoplus try in the model 'year' => 'date:d-m-Y' and then call it with ->format('d-m-Y')

marcoplus's avatar

@NekaDava Thanks for the support but nothing yet it doesn't work I always get the same result, yes I changed the model, I made a mistake and I didn't notice but nothing to do it doesn't work and I can't understand why, where am I wrong

Fields\Date::make('year')->type('date')->format('d-m-Y'), <-- not work
Fields\Date::make('year')->format('d-m-Y'), <-- not work
Fields\Text::make('year')->type('date')->format('d-m-Y'), <-- not work


    protected $casts = [
        'created_at' => 'datetime:d-m-Y H:i:s',
        'updated_at' => 'datetime:d-m-Y H:i:s',
        'anno' => 'date:d-m-Y',
    ];
NekaDava's avatar

@marcoplus Double-check in the front end you have same size of table columns and the data names are same as in the back end

marcoplus's avatar

@NekaDava If I remove this and put this on I see everything perfectly

Fields\Date::make('year')->format('d-m-Y'), <-- remove
Fields\Text::make('year')->format('d-m-Y'), <-- ok but it is not a date field just a text field
DhPandya's avatar

@marcoplus Does your year field exist in the table? If not then you have to $appends property within the model.

$appends = ['your_date_field'];

then add Attributes for it.

protected function yourDateField(): Attribute
    {
        return Attribute::make(
            get: fn ($value) => $value ? Carbon::parse($value)->format('d-M-Y') : null,
            set: fn ($value) => $value ? Carbon::parse($value)->format('Y-m-d') : null, // use only if your field is different datetime format then Y-m-d
        );
    }
marcoplus's avatar

@DhPandya nothing doesn't work, thanks for your support but it doesn't work it's always the same the bar and values ​​disappear, I think it's a bug because it's not possible I've tried everything but it doesn't work

yajra's avatar

You can use wireFormat along with displayFormat:

Fields\DateTime::make('created_at')
    ->wireFormat('YYYY-MM-DDTHH:mm:ss.000000Z')
    ->displayFormat('MM/DD/YYYY HH:mm:ss')
    ->label('Created At'),

wireFormat represents the default date serialization of Laravel in JS date format. This will also be the format that will be submitted in the form request.

displayFormat as the method states, will display the date picker value in the format the user wants.

Please or to participate in this conversation.