Download the PHP package shayanys/lara-reserve without Composer
On this page you can find all versions of the php package shayanys/lara-reserve. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package lara-reserve
Lara Reserve
Lara Reserve Is a Laravel Package To Adds a Reservation feature to the laravel models.
Installation
To Install Lara Reserve Run Following Command:
and then run Migrations By:
Usage
Initialize Models to Use Lara Reserve
To Add Lara Reserve Feature To Models, Your Models Should Implement ReservableInterface
And use Reservable
Trait.
And the Model Is Ready For Reserve By the Customer. And If Your Model Is a Customer, e.g. User model (Which Can Reserve
Reservables) Should Implement CustomerInterface
And use Customer
Trait.
Example:
Reservable Model:
Reservable Model:
Reservations
Call reserve
Method From Customer
you can reserve a reservable for a customer by reserve method of a customer model:
in the above example, $reservable
will reserve for $customer
.
Parameters
- reservable you want to reserve for customer
- the desired date for the reservation
- the desired time for the reservation in H:i:s format
- the desired date for the end reservation - optional
- the desired time for the end reservation in H:i:s format - optional
- additional details for the reservation - optional
Call reserveForCustomer
Method From Reservable
In the above example, like the previous example, $reservable
will reserve for $customer
. In the reserveFroCustomer
Parameters
- the customer would you like to make a reservation for
- the desired date for the reservation
- the desired time for the reservation in H:i:s format
- the desired date for the end reservation - optional
- the desired time for the end reservation in H:i:s format - optional
- additional details for the reservation - optional
Call reserveWithoutCustomer
Method From Reservable
With this method, you can reserve a reservable without a customer.
Parameters
- array of the reservation details
- the desired date for the reservation
- the desired time for the reservation in H:i:s format
- the desired date for the end reservation - optional
- the desired time for the end reservation in H:i:s format - optional
Max allowed reserves
Setting the maximum possible number of reservations on one date and time.
to set maximum allowed reserve in one date you should add max_allowed_reserves
column to your reservable table in
database:
you can set max_allowed_reserves
column of a reservable by calling maxAllowedReserves
from reservable:
this method get $max
to set it as value of max_allowed_reserves
column.
if you want to get the max_allowed_reserves
from reservable you can do this:
returns null if not exists or its null in database.
Is available
isAvailable
method can call from reservable and get two arguments date and optional time; and returns is that
reservable available in passed date and time (the time default is 00:00:00).
This code returns true if max_allowed_reserves
is less than count of all reserves in 2023-05-1 17:00:00; otherwise returns false.
withoutCheckAvailability and withCheckAvailability
if you don't want to check the availability for some reasons you can use withoutCheckAvailability
method:
this code will bypass the check availability.
also you can set reservable to don't check availability by default:
other way to modify this is to modify shouldCheckAvailability
method:
this will don't check availability by default. if you want check availability when you set checkAvailability
property in constructor to false you should do this:
this will check availability and then reserve.
Get Reserves
you can get reserves from customer or reservable.
activeReserves
the activeReserves
method return a MorphMany relation you can call get
method to get the collection of reserves; you can also call paginate
method.
allReserves
the allReserves
method return a MorphMany relation you can call get
method to get the collection of reserves; you can also call paginate
method.
startedReserves
the startedReserves
method return a MorphMany relation you can call get
method to get the collection of reserves; you can also call paginate
method.
endedReserves
the endedReserves
method return a MorphMany relation you can call get
method to get the collection of reserves; you can also call paginate
method.
License
Freely distributable under the terms of the MIT license.