简体   繁体   English

是否可以防止时间字段在 Laravel 背包中期待秒数?

[英]Is it possible to prevent the time field to expect seconds in Laravel Backpack?

I'm working with Laravel Backpack and for a specific model I want the user to be able to add a "start time" using the time field type.我正在使用 Laravel 背包,对于特定的 model,我希望用户能够使用time字段类型添加“开始时间”。 I want the user to enter this format: hh:mm .我希望用户输入这种格式: hh:mm

While creating the entity it works fine.在创建实体时它工作正常。 But in the edit mode the value of the input field has this format: hh:mm:ss但在编辑模式下,输入字段的值具有以下格式: hh:mm:ss

The field is declared like this:该字段声明如下:

[
    'name'  => 'start_time',
    'label' => "Beginn",
    'type'  => 'time'
],

The corresponding field in the DB looks like this:数据库中的相应字段如下所示:

$table->time('start_time')->nullable();

When the model is created this works as expected what means, that I can enter the time in hh:mm format.当创建 model 时,它按预期工作,这意味着我可以以hh:mm格式输入时间。 For example I enter "14:00".例如我输入“14:00”。

After saving the model, in the DB I have the value stored as 14:00:00 .保存 model 后,在数据库中我将值存储为14:00:00

Now, when I go to the edit view the value in the corresponding time input field is also 14:00:00 .现在,当我 go 到编辑视图时,相应时间输入字段中的值也是14:00:00

I assume this is because in the DB the value is stored including the seconds.我认为这是因为在数据库中存储的值包括秒数。

Is it possible to store a time in the DB without the seconds?是否可以在没有秒数的情况下将时间存储在数据库中? So just in the format hh:mm ?所以只是格式hh:mm

For more details I have some screenshots that show what I meant:有关更多详细信息,我有一些屏幕截图可以显示我的意思:

  1. On creation enter image description here enter image description here创建时在此输入图像描述在输入图像描述

  2. The value in DB after saving enter image description here保存后数据库中的值enter image description here

  3. The input after loading the edit view enter image description here加载编辑视图后的输入enter image description here

I think you can make it work by defining the step attribute in the field https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/time#using_the_step_attribute我认为您可以通过在字段https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/time#using_the_step_attribute中定义step属性来使其工作

Cheers干杯

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM