jefsev
04/14/2023, 2:01 PMjefsev
04/14/2023, 2:03 PMhttps://cdn.discordapp.com/attachments/1096435065526952046/1096435469723631706/image.png▾
ifox
04/14/2023, 2:28 PMifox
04/14/2023, 2:28 PMjefsev
04/14/2023, 3:16 PMjefsev
04/14/2023, 3:17 PMjefsev
04/14/2023, 3:19 PMpublic $casts = [
'publish_start_date' => 'datetime',
'publish_end_date' => 'datetime'
];
jefsev
04/14/2023, 3:19 PMjefsev
04/14/2023, 3:24 PMLucius Vorenus
04/14/2023, 3:44 PMpublic function publishEndDate(): Attribute
{
return Attribute::make(
get: fn (string|null $value) => $this->formatDate($value, 'get'),
set: fn (string|null $value) => $this->formatDate($value)
);
}
protected function formatDate($value, $action='set'): string|null{
if ($value === null) return null;
$time = new Carbon($value);
if ($action =='get'){
$time->toFormattedDateString();
}
else {
$time->toDateTimeString();
}
return $time;
}
Somebody else could probably write that in one or two lines!Lucius Vorenus
04/14/2023, 4:12 PMpublish_start_date
, you can override a function in model.php
.
public function setPublishStartDateAttribute($value): void
{
$this->attributes['publish_start_date'] = (new Carbon($value))->format('Y-m-d H:i:s');
}
Just adding this for completeness.
It struck me for both these fields, that it was the datepicker was just being awks!ifox
04/14/2023, 4:23 PMifox
04/14/2023, 4:23 PMLucius Vorenus
04/14/2023, 4:28 PMLucius Vorenus
04/14/2023, 4:31 PMifox
04/14/2023, 4:47 PM$table->timestamp('publish_start_date')->nullable();
$table->timestamp('publish_end_date')->nullable();
model
public $casts = [
'publish_start_date' => 'datetime',
'publish_end_date' => 'datetime'
];
ifox
04/14/2023, 4:47 PMLucius Vorenus
04/14/2023, 4:48 PMifox
04/14/2023, 4:48 PMhttps://cdn.discordapp.com/attachments/1096435065526952046/1096477162841854173/Screenshot_2023-04-14_at_6.48.41_PM.png▾
ifox
04/14/2023, 4:48 PMifox
04/14/2023, 4:48 PMLucius Vorenus
04/14/2023, 4:52 PMifox
04/14/2023, 5:06 PMlaravel new twill-3-publication-dates
cd twill-3-publication-dates
composer require area17/twill:"^3.0"
php artisan twill:install basic-page-builder
then uncommented the publish_start_date
and publish_end_date
in the generated migration and added them to the model fillable and casts. no issues. also tried to use stability at dev and composer update, still no issues.Lucius Vorenus
04/14/2023, 6:58 PMLucius Vorenus
04/16/2023, 12:28 PM'published_start_date' => 'datetime'
and 'published_start_date' => 'datetime:Y-m-d H:i:s'
for both fields.
Any time the datepicker is used, up pops this error. Doesn't matter if date picked is before now() or later in either field.
If status is changed from draft to published, the start date is added by the system, and correctly stored in the database, then correctly retrieved and displayed by the datepicker, next time form is opened.
Using the datepicker to change this value results in the same error.
I am curious what's causing this, but not sure it's worth any more time, by either me, nor, particularly, you! I think there may be an implication that is something outside the laravel / twill setup.
FYI Ubuntu 22.04.2 Apache 2.4.57 mysql 8.0.32
(It's Sunday, and I'm off to make curry!)
https://cdn.discordapp.com/attachments/1096435065526952046/1097136409296502864/date_save_error.png▾
jefsev
04/17/2023, 8:31 AM$table->timestamp('publish_start_date')->nullable();
$table->timestamp('publish_end_date')->nullable();
public $casts = [
'publish_start_date' => 'datetime',
'publish_end_date' => 'datetime'
];
But it's now showing for me in the cms.jefsev
04/17/2023, 8:35 AMjefsev
04/17/2023, 8:36 AMjefsev
04/17/2023, 8:37 AMjefsev
04/17/2023, 8:43 AMjefsev
04/17/2023, 8:44 AMjefsev
04/17/2023, 8:58 AMhttps://cdn.discordapp.com/attachments/1096435065526952046/1097445898516168765/Screenshot_2023-04-17_105657.png▾
jefsev
04/17/2023, 8:58 AMjefsev
04/17/2023, 8:59 AMifox
04/17/2023, 9:10 AMLucius Vorenus
04/17/2023, 9:55 AMjefsev
04/17/2023, 9:57 AMjefsev
04/17/2023, 9:57 AMjefsev
04/17/2023, 9:57 AMjefsev
04/17/2023, 9:57 AMjefsev
04/17/2023, 9:58 AMjefsev
04/17/2023, 9:58 AMifox
04/17/2023, 10:00 AMjefsev
04/17/2023, 10:17 AMLucius Vorenus
04/17/2023, 10:50 AMifox
04/17/2023, 11:05 AMjefsev
04/17/2023, 12:42 PMifox
04/17/2023, 12:46 PMLucius Vorenus
04/18/2023, 4:29 PMifox
04/18/2023, 5:16 PMLucius Vorenus
04/18/2023, 5:36 PMimage_url
, as I thought I would be saving an image url for the opengraph photo for the article. As such it was added to the fillables
property.
I ended up using that field name in a component block (article header) which saved and displayed as expected.
Creating a new componentBlock, image
, with exactly the same logic, but a different field name (article_image
), I could not get the image to save (crops had been added for article_image
).
It indicated that all had saved correctly, but either viewing it, or reloading the form after the update showed it as missing. Adding article_image
to the fillables on the model fixed the problem (though I'm still wrangling over crops, and whether their exists a default set in twill).ifox
04/18/2023, 5:39 PMcover
, it's here https://github.com/area17/twill/blob/9d53e795732521d1515661f12ba793dcee21d7b4/config/twill.php#L239. for blocks, it works by default if the field is named image
. Configuration is here https://github.com/area17/twill/blob/9d53e795732521d1515661f12ba793dcee21d7b4/config/block_editor.php#L23. any medias field that you add to your form or a block needs a corresponding crop configuration.ifox
04/18/2023, 5:40 PMLucius Vorenus
04/18/2023, 5:40 PMLucius Vorenus
04/19/2023, 10:22 AM