datasdk/available
最新稳定版本:1.0
Composer 安装命令:
composer require datasdk/available
包简介
Available model and traits for MyProject
README 文档
README
This package provides an Available model and trait that can be used to add a polymorphic availability period to any Eloquent model.
Installation
composer require datasdk/available
Usage On A Model
Add the trait to the model that should support availability:
use MyProject\Available\Traits\Available; class Event extends Model { use Available; }
The trait stores availability records through the following model:
use MyProject\Available\Models\Available;
Relationships
available()
Returns the related availability record as a morphOne relationship.
$event->available;
availability()
Returns the inverse polymorphic relationship from the availability model.
Methods
set_available(array $dates)
Creates or updates the availability period for the model.
$event->set_available([ 'from' => '2026-06-01 09:00:00', 'to' => '2026-06-01 17:00:00', ]);
If both from and to are empty, the model is marked as always available.
set_available_from($from)
Sets only the start datetime.
$event->set_available_from('2026-06-01 09:00:00');
set_available_to($to)
Sets only the end datetime.
$event->set_available_to('2026-06-01 17:00:00');
Query Scopes
available()
Returns models that are available now.
Event::available()->get();
availableFrom($from)
Returns models based on a start datetime.
Event::availableFrom('2026-06-01')->get();
availableTo($to)
Returns models based on an end datetime.
Event::availableTo('2026-06-30')->get();
availableAt($date)
Returns models that are available at a specific datetime.
Event::availableAt('2026-06-15 12:00:00')->get();
availableAtDate($date)
Works like availableAt, but compares only the date part.
Event::availableAtDate('2026-06-15')->get();
availableBetween($from, $to)
Returns models whose availability overlaps a datetime range.
Event::availableBetween('2026-06-01', '2026-06-30')->get();
availableBetweenDate($from, $to)
Returns models whose availability overlaps a date range without comparing time.
Event::availableBetweenDate('2026-06-01', '2026-06-30')->get();
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-05-12