sucohi / time-label
Laravel 包,用于管理时间标签,如“本月”等。
2.0.1
2015-10-17 03:23 UTC
Requires
- laravel/framework: ~5.0
This package is not auto-updated.
Last update: 2024-09-14 17:48:18 UTC
README
Laravel 包,用于管理时间标签,如 本月
等。
安装
在 composer.json 中添加此包名
"require": {
"sukohi/time-label": "2.*"
}
执行 composer 命令。
composer update
在 app.php 中注册服务提供者
'providers' => [
...Others...,
Sukohi\TimeLabel\TimeLabelServiceProvider::class,
]
别名
'aliases' => [
...Others...,
'TimeLabel' => Sukohi\TimeLabel\Facades\TimeLabel::class
]
用法
$time_label = TimeLabel::setLabel([
'today' => 'Today',
'yesterday' => 'Yesterday',
'this_month' => 'This Month',
'last_month' => 'Last Month',
'other' => 'M, Y' // You need to set date format only here.
]);
$date_times = [
Carbon::now(),
Carbon::now(),
Carbon::now()->subDay(),
Carbon::now()->subDay(),
Carbon::now()->subDays(2),
Carbon::now()->subDays(4),
Carbon::now()->subDays(4),
Carbon::now()->subDays(5),
Carbon::now()->subDays(10),
Carbon::now()->subDays(20),
Carbon::now()->subDays(50),
Carbon::now()->subDays(150),
];
foreach($date_times as $dt) {
if($time_label->isFirst($dt)) {
echo $time_label->get($dt) .'<br>';
}
echo $dt .'<hr>';
}
许可证
此包采用 MIT 许可证授权。
版权所有 2015 Sukohi Kuhoh