Download the PHP package binary-cats/coordinator without Composer
On this page you can find all versions of the php package binary-cats/coordinator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download binary-cats/coordinator
More information about binary-cats/coordinator
Files in binary-cats/coordinator
Package coordinator
Short Description Schedule and manage resource booking (appointments) in your Laravel app
License MIT
Homepage https://github.com/binary-cats/coordinator
Informations about the package coordinator
Coordinator
Coordinator is a generic resource booking system for Laravel, built with simplicity in mind. It will allow you to book (or schedule) resources using simple intuitive API.
The package is built with expectations that you would probably extending it for you own needs, so very few conventions are used. Please make sure to familiarize yourselves with the concepts.
Installation
You can install the package via composer:
The Service Provider will automatically register itself and add the following configuration to your Laravel installation:
To change anything in the setup, you can publish the config file using
Config file will be published at config/coordinator.php
:
Migration
Running the following will publish a single migration for bookings table:
Concepts
The package provides you with a single model: Booking.
Booking Model
Booking
is a single record that ties together bookable resource, like a Room
or Table
or TechSupport
and the model that books the resource. Since the word book is present in every word, it may be hard to grasp right away. In essence, Booking
is a pivot model, that has two polymorphic keys: model
which represents the owner of the relationship and resource
, representing, well, a resource we want to book.
A simple example, perhaps, will help:
When a customer wants to rent an room, we have a relationship between a Customer and a Resource they want.
Customer is a model
and a Room is a resource
and their relationship is stored as a Booking
.
Availability
It is not expected that you may want to have overlapping booking of resources, but nothing should stop you from trying!
There are legitimate use cases when you may want to create two bookings and whomever confirms first, gets the slot and the other gets cancelled.
Coordinator will not try to force your hand, but that means that you need to implement this logic yorself.
Usage
Let's prepare our models. First, the resource that can be booked:
Notice that Resource is implementing BinaryCats\Coordinator\Contracts\BookableResource
.
Now, a model that books resources:
Notice that Model is implementing BinaryCats\Coordinator\Contracts\CanBookResources
.
Just like with notifications, you should not be bound by thinking "it is a user that books something". Any model can be booking any other resource; a Driver user can be booked by a Delivery for instance.
Coordinator offers fluent interface to create a booking, that can be used on either side of the relation:
and
will produce identical result.
Checking availability
Bookable resource provides means of checking if it is available or booked at a given moment:
To check if the Room
is available at a given moment with isAvailableAt
. The first argument can be any implementation of DateTimeInterface
that can be converted to Carbon\Carbon
instance, a string or even a Period:
To check if the Room
is available on '2021-01-01', you can use isAvailableAt
:
You can pass the second argument to account for the bookings that are canceled:
You can check if the Room
is booked at a given moment with isBookedAt
:
You can pass the second argument to account for the bookings that are canceled:
Advanced usage
You can check if the Resource is booked or available against a period as well. When doing so, you need to make sure you are comparing period with the same precision. The easiest way is to simply rely on the setting of the Coordinator itself:
By default Coordinator will look for SECOND
as precison. You can change that by updating coordinator.precision
config key.
More about period calculations here;
You can also check if the Resource is available for a given Model. However, since this is more of a policy concern, you need to provide closure resolution logic. For example, you may want to defer to authorization logic using a Gate:
or anything else:
Changelog
Please see CHANGELOG for more information about what has changed recently.
Testing
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email [email protected] instead of using issue tracker.
Postcardware
You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.
Credits
- Cyrill Kalita
- All Contributors
Support us
Binary Cats is a webdesign agency based in Illinois, US.
License
The MIT License (MIT). Please see License File for more information.
All versions of coordinator with dependencies
illuminate/support Version ^8.0|^9.0
spatie/laravel-package-tools Version ^1.0
spatie/period Version ^2.0