我恳求您的支持,以了解如何将原始资源中所示的相同日期格式应用于 Laravel Nova 4 中的
belongsTo
字段。
资源1
public function fields(Request $request)
{
return [
ID::make('id')->sortable(),
Date::make('Shipment Eta Date')
->rules('required', 'date')
->placeholder('Shipment Eta Date')
->displayUsing(fn ($value) => $value ? $value->format('D d/m/Y') : ''),
HasMany::make('ShipmentInfos', 'shipmentInfos'),
];
}
资源2
public function fields(Request $request)
{
return [
ID::make('id')->sortable(),
Date::make('Shipment Sent Date')
->rules('required', 'date')
->placeholder('Shipment Sent Date')
->displayUsing(fn ($value) => $value ? $value->format('D d/m/Y') : ''),
HasMany::make('ShipmentInfos', 'shipmentInfos'),
];
资源3
BelongsTo::make('ShipmentSentDate', 'shipmentSentDate'),
BelongsTo::make('ShipmentEtaDate', 'shipmentEtaDate'),
我尝试过这个,但不起作用:
BelongsTo::make('ShipmentSentDate', 'shipmentSentDate')
->displayUsing(fn ($value) => $value ? $value->format('D d/m/Y') : ''),
BelongsTo::make('ShipmentEtaDate', 'shipmentEtaDate')
->displayUsing(fn ($value) => $value ? $value->format('D d/m/Y') : ''),
对于给您带来的不便,我深表歉意,并感谢@Harris。解决办法如下:
BelongsTo::make('ShipmentSentDate', 'shipmentSentDate')
->displayUsing(function ($shipmentSentDate) {
return Carbon::now()->format('Y-m-d');
}),
谢谢你。