我试图从 08:00:00 到 08:00 获取 TimeString。
我想这样投射时间:
protected $casts = [
'opens' => 'time:H:i',
'closes' => 'time:H:i',
];
Run Code Online (Sandbox Code Playgroud)
不使用像 getOpensAttribute() 这样的修改器。
在我的迁移中,我正在使用:
$table->time('opens')->nullable();
$table->time('closes')->nullable();
Run Code Online (Sandbox Code Playgroud)
是否可以?
小智 7
我认为你可以创建一个自定义演员表,例如:
使用以下命令生成自定义演员表:
php artisan make:cast TimeCast
Run Code Online (Sandbox Code Playgroud)
时播
public function get($model, string $key, $value, array $attributes)
{
return Carbon::parse($value)->format('H:i');
}
Run Code Online (Sandbox Code Playgroud)
最后你可以用它作为
protected $casts = [
'your_time_to_cast' => TimeCast::class
];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3975 次 |
| 最近记录: |