承接 masterix21/laravel-bookings 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

masterix21/laravel-bookings

Composer 安装命令:

composer require masterix21/laravel-bookings

包简介

Add bookings ability to any Eloquent model

README 文档

README

Latest Version on Packagist Tests PHP Version Total Downloads

Add booking functionality to any Eloquent model. Turn your models into bookable resources with time-based reservations, capacity management, planning constraints, overlap detection, and an event-driven architecture.

Table of Contents

Features

  • 🚀 Make any Eloquent model bookable with a single trait
  • 📅 Advanced time period management powered by spatie/period
  • 🏢 Resource capacity control with configurable concurrency limits
  • 📋 Planning constraints for weekday and time-window restrictions
  • 🔍 Overlap detection and conflict prevention
  • 🎯 Event-driven architecture for audit trails and integrations
  • 🗂️ Polymorphic relationships for flexible booker and resource types
  • 🔗 Related bookings with parent-child relationships
  • 🔄 Automatic synchronization of resources and planning via model events
  • 🛡️ Transaction safety with automatic rollback on failures

Requirements

Requirement Version
PHP 8.4+
Laravel 12.x or 13.x

Installation

Install the package via Composer:

composer require masterix21/laravel-bookings

Publish and run the migrations:

php artisan vendor:publish --tag="bookings-migrations"
php artisan migrate

Optionally, publish the config file:

php artisan vendor:publish --tag="bookings-config"

See the installation guide for optional migrations and upgrade notes.

Quick Start

1. Make a model bookable

Add the IsBookable trait to any model. A BookableResource is created and kept in sync automatically.

use Masterix21\Bookings\Models\Concerns\Bookable;
use Masterix21\Bookings\Models\Concerns\IsBookable;

class Room extends Model implements Bookable
{
    use IsBookable;

    protected $fillable = ['name', 'capacity'];
}

2. Configure the bookable resource

Each bookable model exposes its BookableResource, where you set availability and capacity:

$room = Room::create(['name' => 'Deluxe Suite', 'capacity' => 4]);

$room->bookableResource->update([
    'max' => 1,            // Maximum concurrent bookings
    'size' => 4,           // Resource capacity
    'is_bookable' => true,
    'is_visible' => true,
]);

3. Make a booking

use Masterix21\Bookings\Actions\BookResource;
use Spatie\Period\Period;
use Spatie\Period\PeriodCollection;

$periods = PeriodCollection::make([
    Period::make('2024-12-25', '2024-12-27'),
]);

$booking = (new BookResource())->run(
    periods: $periods,
    bookableResource: $room->bookableResource,
    booker: auth()->user(),
    label: 'Christmas Holiday',
    meta: ['guests' => 2],
);

Overlapping bookings are rejected automatically:

use Masterix21\Bookings\Exceptions\BookingResourceOverlappingException;

try {
    $booking = (new BookResource())->run(/* ... */);
} catch (BookingResourceOverlappingException $e) {
    return response()->json(['error' => 'Time slot already booked'], 409);
}

See the getting started guide for a full walkthrough.

Core Concepts

Concept Description
BookableResource The bookable item, linked to your model (Room, Car, …) via a polymorphic relation.
Booking A reservation with booker, metadata, and one or more time periods.
BookedPeriod An individual time slot within a booking, enabling multi-period reservations.
BookablePlanning Availability rules: working days, time windows, and constraints for a resource.

Advanced Features

Each feature below is summarized here and documented in full under docs/.

Booking lifecycle callbacks

Hook custom logic before and after a booking is persisted with onBookingSaving() and onBookingSaved() — useful for multi-tenancy, logging, or side effects. → docs/actions.md

Custom resource synchronization

Add the SyncBookableResource trait and implement syncBookableResource() to push data from your model (visibility, capacity, availability) into its BookableResource automatically on save. → docs/synchronization.md

Planning source pattern

Add the SyncBookablePlanning trait so a business model (rate, special offer, seasonal rule) becomes the single source of truth for a resource's availability, with bidirectional navigation between source and planning. → docs/synchronization.md

Related bookings

Link bookings with parent-child relationships (room + parking, appointment + follow-up). Each booking keeps an independent lifecycle, and children survive parent deletion. Requires an optional migration. → docs/related-bookings.md

Planning constraints

Define when a resource can be booked through BookablePlanning records — available weekdays plus starts_at/ends_at windows. → docs/models.md

Events

The booking lifecycle emits events (BookingInProgress, BookingCompleted, BookingFailed, BookingChanging, BookingChanged, BookingChangeFailed) for audit trails and integrations. → docs/events.md

Checking availability

$room->isBookedAt(now());            // bool
$room->bookedPeriodsOfDate(today()); // booked periods for a date
$room->bookings;                     // all bookings for the resource

Documentation

Guide Description
Getting Started Step-by-step quick start
Installation Installation and optional migrations
Configuration Configurable models and generators
Architecture Package design and structure
Models Model relationships and usage
Actions Core booking operations
Synchronization Resource and planning synchronization
Events Event system and listeners
Database Schema Tables and migrations
API Reference Complete API documentation
Migration Guide Upgrading between versions
Extending Customization and extension points
Troubleshooting Common issues and solutions

Examples

Testing

composer test           # run the test suite
composer test-coverage  # run with coverage
composer analyse        # run static analysis (PHPStan)

See docs/testing.md for testing strategies.

Contributing & Credits

Created and maintained by Luca Longo and all contributors.

License

The MIT License (MIT). See the License File for details.

masterix21/laravel-bookings 适用场景与选型建议

masterix21/laravel-bookings 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 68 次下载、GitHub Stars 达 4, 最近一次更新时间为 2025 年 07 月 29 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「LucaLongo」 「laravel-bookings」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 masterix21/laravel-bookings 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 masterix21/laravel-bookings 我们能提供哪些服务?
定制开发 / 二次开发

基于 masterix21/laravel-bookings 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

与 masterix21/laravel-bookings 相关的其它包

同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:

统计信息

  • 总下载量: 68
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 17
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-07-29