Open dmitriytretyakov opened 4 years ago
What about fix? Version: dev-master 232b476
I have this issue too. Any progress on this ? Tried casts both on layout and model. No luck. Thanks
The issue appears only in view page as you say, but I am getting the error message about cast also in deletion and I am not able to delete the entry.
Confirming the same issue here. Using latest version too
My custom layout:
namespace App\Nova\Flexible\Layouts;
use App\Src\MyCity\FlexibleConstruct;
use Illuminate\Support\Collection;
use Laravel\Nova\Fields\Boolean;
use Laravel\Nova\Fields\Date;
use Laravel\Nova\Fields\Text;
use Whitecube\NovaFlexibleContent\Flexible;
use Whitecube\NovaFlexibleContent\Layouts\Layout;
class Schedules extends Layout
{
/**
* The layout's unique identifier
*
* @var string
*/
protected $name = 'schedules';
/**
* The displayed title
*
* @var string
*/
protected $title = 'Schedules';
protected $casts = [
'starts' => 'date',
'ends' => 'date',
'every_year' => 'boolean',
'always_open' => 'boolean',
];
/**
* The storage format of the model's date columns.
*
* @var string
*/
protected $dateFormat = 'Y-m-d';
/**
* Get the fields displayed by the layout.
*
* @return array
* @throws \Exception
*/
public function fields()
{
return [
Date::make('Du', 'starts')
->sortable(),
Date::make('Au', 'ends')
->sortable(),
Boolean::make('Chaque année', 'every_year')->sortable()
->help("L'objet se déroule chaque année au même moment"),
Flexible::make('Ouvertures', 'openings')
->addLayout(Openings::class)
->addLayout('Fermetures', 'closures', [
Text::make('Du', 'from')
->withMeta([
'type' => 'date',
]),
Text::make('Au', 'to')
->withMeta([
'type' => 'date',
]),
])
->button('Ajouter des horaires')->hideFromIndex(),
];
}
}
@Nyratas do you think you can make some time for this soon? If it prevents deleting layouts it's a pretty major bug.
Unable to load a resource with datetime error (with custom layout defined).
Problem appear on View (detail) page and DELETE action. No problem on edit
you have to handle mannualy the conversion of the date fields if you have a filed struckure like this:
Flexible::make(('Blackout'))->addLayout( ('Blackout'), 'blackout', [ Date::make(('Startdate'), 'startdate') ->hideFromIndex() ->sortable(), Date::make(('Enddate'), 'enddate') ->hideFromIndex() ->sortable(), ]) ->button(__('Add blackout'))
you have to define a mutator for this blackout attribute named "getBlackoutAttribute" in your model
public function getBlackoutAttribute($value)
{
if(\is_string($value)){
$value = json_decode($value, true);
foreach ($value as $key => $oneBlackOut) {
$this->toCarbon($oneBlackOut, 'attributes.startdate');
$this->toCarbon($oneBlackOut, 'attributes.enddate');
$value[$key] = $oneBlackOut;
}
}
return $value;
}
protected function toCarbon(&$srcArr, $key)
{
$carbonDate = new Carbon(data_get($srcArr, $key));
data_set($srcArr, $key, $carbonDate);
}
Doesn't help for me
Any progress on this? I'm having the same issue
Thank's vmihaly2020,
I just had to use Laravel Carbon and I did it inside the foreach but that's perfect.
foreach ($value as $key => $dateInflexible) {
$value[$key]['attributes']['start_at'] = Carbon::createFromFormat("Y-m-d H:i:s", $dateInflexible['attributes']['start_at']);
$value[$key]['attributes']['end_at'] = Carbon::createFromFormat("Y-m-d H:i:s", $dateInflexible['attributes']['end_at']);
}
You can use resolveUsing()
to override the default Datetime resolver.
DateTime::make('Date')
->format('DD/MM/YYYY HH:mm')
->resolveUsing(function ($value) {
return $value;
}),
@Broutard thanks! that worked for me
@Broutard Lifesafer! Should be in the docs.
Thank you for your solution. It works for me. @Broutard Do you know how to remove the selection of the date from the calendar popup? This means we want only a selection of the month and year in the date picker popup. Screenshot: http://prntscr.com/1r0xi1y
You can use
resolveUsing()
to override the default Datetime resolver.DateTime::make('Date') ->format('DD/MM/YYYY HH:mm') ->resolveUsing(function ($value) { return $value; }),
This is the solution. 🎉
Yeh cool but doesn't it say this though? https://share.getcloudapp.com/4gue5K1A - where did the format come from lol. I'll try with just resolveUsing and if it work syou're a genius!
Without format (in case if db contains different formats and you need standartise)
Date::make('Date', 'date')
->resolveUsing(function ($value) {
if($value) {
try {
return Carbon::parse($value);
} catch (\Exception $e) {
}
}
return null;
}),
Without format (in case if db contains different formats and you need standartise)
Date::make('Date', 'date') ->resolveUsing(function ($value) { if($value) { try { return Carbon::parse($value); } catch (\Exception $e) { } } return null; }),
Thank you!
Hi, i already write issue https://github.com/whitecube/nova-flexible-content/issues/151 and https://github.com/whitecube/nova-flexible-content/issues/14 doesn't help me.
Bug appears only on view page, edit page is fine.
My layout code is:
What's wrong?