can anyone spot what i am doing wrong here?
I am trying to display a hyphen if there is no date added to the record
this is my code
Any ideas where i am going wrong ?
18 Replies
Solution
You can try ->default('-')
oh my gosh so easy! Thank you sire!
actually spoke a litle fast - it worked initially, then i set a date, then removed it and now get this error
Could not parse '-': Failed to parse time string (-) at position 0 (-): Unexpected character @DysonSphere
Where did you put the ->default('-')?
If you remove the ->date(), there will be no error
yes but it wont format the date then on the table when there is a value
You were on the right track to start with. Change ‘$value’ to ‘$state’ in the formatStateUsing() modifier.
sorry for being a bit thick here!!
you mean like
- it doesnt work
Can you dd($state) it may not be null.
it doesnt seem to even hit the formatStateUsing method when i add the dd in their - the record column for due_date in teh db is NULL though
this is a gist https://gist.github.com/craigvc/a0d1892d400568292f46d56dde8d0b65
Have i done something wrong?
give me a minute. gonna check on something. i would expect it to work.
hmm. not sure why formatStateUsing isn't getting called when the initial value is null
either way, even if you fake it with getStateUsing() you're going to have a problem because the ->date() modifier will break trying to parse '-' into a Carbon instance.
I think the only way your going to be able to do this to not use ->date() and return your own formatted string for it.
I am getting Call to a member function toDateTimeString() on string with that (though in my model i have protected $dates = ['due_date', 'start_date', 'completed_date']; ) so it should be a date?
it should be cast to a carbon instance. it shouldn't be a string
that code works in the Filament demo
so on the form the date is added DatePicker::make('due_date')->prefix('Due Date')->label('')->native(false)->columnSpan(3),
In the Db its stored as datetime
I am a bit stumped where i am wrong here?
maybe trying casting them directly instead of using the $dates property.
That was it !
I tweaked a little so we can pull the user date format later to this
->formatStateUsing(function ($record) { if ($record->due_date !== null) { return $record->due_date->format('Y-m-d'); } return '-'; }) Which seems to work! Thanks for your help!!!!
->formatStateUsing(function ($record) { if ($record->due_date !== null) { return $record->due_date->format('Y-m-d'); } return '-'; }) Which seems to work! Thanks for your help!!!!