moonshiner / safe-queuing
用于管理时间段的预定和预约的包
1.0.0
2021-03-15 13:34 UTC
Requires
- php: ^7.1
- illuminate/support: ^8.0
Requires (Dev)
- orchestra/testbench: ^4.0
- phpunit/phpunit: ^8.0
README
此包可以帮助您将时间段和预约功能附加到现有的Laravel Eloquent模型中。
安装
您可以通过composer安装此包
composer require moonshiner/safe-queuing
您可以使用此包进行时间段的计算。要使用包的预约功能,您需要发布迁移。如果您想更改表名,还需要发布配置。要运行发布命令,您需要添加服务提供者
// config/app.php 'providers' => [ // ... Moonshiner\SafeQueuing\SafeQueuingServiceProvider::class, ];
如果您想指定一个自定义的表名,您需要发布并编辑配置文件
php artisan vendor:publish --provider="Moonshiner\SafeQueuing\SafeQueuingServiceProvider" --tag="config"
发布迁移以使用预约功能
php artisan vendor:publish --provider="Moonshiner\SafeQueuing\SafeQueuingServiceProvider" --tag="migrations" php artisan migrate
用法
您可以通过HasTimeslots
特质简单地将时间段添加到现有的模型中。
use Moonshiner\SafeQueuing\HasTimeslots; //... class Event extends Model { use HasTimeslots;
为了更好地配置时间段的约束,您可以将以下函数添加到模型中,以配置时间段何时可用
public function timeslotStartDate(){ return \Carbon\Carbon::now(); } public function timeslotEndDate(){} public function timeslotStartTime(){} public function timeslotEndTime(){} public function timeslotDuration(){} public function timeslotBreak(){} public function timeslotAvailableDays(){} public function timeslotExcludedDates(){} public function timeslotIncludedDates(){} public function timeslotExcludedTimes(){}
要显示所有可用的时间段,可以使用
$event = Event::first(); dd($event->timeslots());
要显示所有预约,运行
$event = Event::first(); dd($event->reservations);
您可以过滤时间段
use Carbon\Carbon; $event = Event::first(); // timeslots after some date dd($event->timeslots()->findSlot(['start'=>Carbon::now(), 'end'=>Carbon::now()->addMinutes('30')])); // only timeslots on a specific date dd($event->timeslots()->onDay(Carbon::today())); // timeslots after some date dd($event->timeslots()->afterDate(Carbon::yesterday())); // timeslots that end before given time dd($event->timeslots()->beforeDate(Carbon::tomorrow()));
要添加预约,运行
$event = Event::first(); $timeslot = $event->timeslots()->first(); $event->reservations()->create([ 'details' => 'Person specific data', 'timeslot' => $timeslot ]);
测试
composer test
变更日志
有关最近更改的更多信息,请参阅CHANGELOG。
贡献
有关详细信息,请参阅CONTRIBUTING。
安全性
如果您发现任何安全相关的问题,请通过office@moonshiner.at而不是使用问题跟踪器来发送电子邮件。
致谢
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。
Laravel包模板
此包是用Laravel包模板生成的。