moonshiner/safe-queuing

Package to manage bookings and reservations for timeslots

1.0.0 2021-03-15 13:34 UTC

This package is auto-updated.

Last update: 2024-10-15 22:45:52 UTC


README

Latest Version on Packagist Total Downloads

This package helps you to attach timeslot and reservation capabilities to your existing Eloquent Models in Laravel.

Installation

You can install the package via composer:

composer require moonshiner/safe-queuing

You can use the package for timeslot calculation only. To use the reservation capabilities of the package you need to publish the migrations. If you want to change the table name publishing the config is necessary as well. To run the publish command you need to add the Service Provider:

// config/app.php
'providers' => [
    // ...
    Moonshiner\SafeQueuing\SafeQueuingServiceProvider::class,
];

If you want to specify a custom table name, you'll need to publish and edit the configuration file:

php artisan vendor:publish --provider="Moonshiner\SafeQueuing\SafeQueuingServiceProvider" --tag="config"

Publishing and running the migrations for the usage of reservations:

php artisan vendor:publish --provider="Moonshiner\SafeQueuing\SafeQueuingServiceProvider" --tag="migrations"
php artisan migrate

Usage

You can simply add timeslots to your existing Model via the HasTimeslots Trait.

use Moonshiner\SafeQueuing\HasTimeslots;

//...

class Event extends Model
{
    use HasTimeslots;

To better configure the contraints for the timeslots you can add the following functions to your model to configure when timeslots are available:

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(){}

To show all the timeslots available you can use:

$event = Event::first();

dd($event->timeslots());

To show all the reservations run:

$event = Event::first();

dd($event->reservations);

You can filter Timeslots

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()));

To add a reservations run:

$event = Event::first();
$timeslot = $event->timeslots()->first();

$event->reservations()->create([
    'details' => 'Person specific data',
    'timeslot' => $timeslot
]);

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email office@moonshiner.at instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Laravel Package Boilerplate

This package was generated using the Laravel Package Boilerplate.