cheeasy-tech/laravel-multibooking

Laravel 多预订实现

dev-main 2024-09-06 00:22 UTC

This package is auto-updated.

Last update: 2024-09-06 00:22:13 UTC


README

Laravel 多预订 是一个灵活的多预订系统,适用于 Laravel 应用。它允许用户预订实现 BookableContract 的各种流程(例如,培训课程、研讨会)。

安装

要安装此包,只需运行

composer require cheeasytech/laravel-multi-booking

发布配置和迁移

安装完成后,您可以发布配置文件和迁移

php artisan vendor:publish --provider="CheesyTech\LaravelBooking\BookingServiceProvider" --tag="config"
php artisan vendor:publish --provider="CheesyTech\LaravelBooking\BookingServiceProvider" --tag="migrations"

运行迁移以创建必要的表

php artisan migrate

配置

config/booking.php 文件中,设置系统的用户模型

return [
    'user_model' => \App\Models\User::class,
];

用法

定义可预订实体

任何可以预订的流程(例如,研讨会或培训课程)都应该实现 BookableContract

例如

namespace App\Models;

use CheeasyTech\LaravelBooking\BookableContract;
use Illuminate\Database\Eloquent\Model;

class TrainingSession extends Model implements BookableContract
{
    public function getBookableId(): int
    {
        return $this->id;
    }

    public function getBookableType(): string
    {
        return static::class;
    }
}

用户预订

用户可以使用 book 方法预订流程(例如,培训课程)。

// Get all bookings for a user
$user->bookings;