PHP code example of rinvex / bookings

1. Go to this page and download the library: Download rinvex/bookings library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rinvex / bookings example snippets


namespace App\Models;

use Rinvex\Bookings\Traits\Bookable;
use Illuminate\Database\Eloquent\Model;

class Room extends Model
{
    use Bookable;
}

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Rinvex\Bookings\Traits\HasBookings;

class Customer extends Model
{
    use HasBookings;
}

$room = \App\Models\Room::find(1);
$customer = \App\Models\Customer::find(1);
$bookableAvailability = app('rinvex.bookings.bookable-booking');

// Create a new booking via resource model (customer, starts, ends)
$room->newBooking($customer, '2017-07-05 12:44:12', '2017-07-10 18:30:11');

// Create a new booking via customer model (resource, starts, ends)
$customer->newBooking($room, '2017-07-05 12:44:12', '2017-07-10 18:30:11');

// Create a new booking explicitly
$bookableAvailability->make(['starts_at' => \Carbon\Carbon::now(), 'ends_at' => \Carbon\Carbon::tomorrow()])
        ->customer()->associate($customer)
        ->bookable()->associate($room)
        ->save();

$bookableAvailability = app('rinvex.bookings.bookable-booking')->find(1);

$bookable = $bookableAvailability->bookable; // Get the owning resource model
$customer = $bookableAvailability->customer; // Get the owning customer model

$bookableAvailability->isPast(); // Check if the booking is past
$bookableAvailability->isFuture(); // Check if the booking is future
$bookableAvailability->isCurrent(); // Check if the booking is current
$bookableAvailability->isCancelled(); // Check if the booking is cancelled

$pastBookings = app('rinvex.bookings.bookable-booking')->past(); // Get the past bookings
$futureBookings = app('rinvex.bookings.bookable-booking')->future(); // Get the future bookings
$currentBookings = app('rinvex.bookings.bookable-booking')->current(); // Get the current bookings
$cancelledBookings = app('rinvex.bookings.bookable-booking')->cancelled(); // Get the cancelled bookings

$bookableAvailabilitysSAfter = app('rinvex.bookings.bookable-booking')->startsAfter('2017-06-21 19:28:51')->get(); // Get bookings starts after the given date
$bookableAvailabilitysStartsBefore = app('rinvex.bookings.bookable-booking')->startsBefore('2017-06-21 19:28:51')->get(); // Get bookings starts before the given date
$bookableAvailabilitysSBetween = app('rinvex.bookings.bookable-booking')->startsBetween('2017-06-21 19:28:51', '2017-07-01 12:00:00')->get(); // Get bookings starts between the given dates

$bookableAvailabilitysEndsAfter = app('rinvex.bookings.bookable-booking')->endsAfter('2017-06-21 19:28:51')->get(); // Get bookings starts after the given date
$bookableAvailabilitysEndsBefore = app('rinvex.bookings.bookable-booking')->endsBefore('2017-06-21 19:28:51')->get(); // Get bookings starts before the given date
$bookableAvailabilitysEndsBetween = app('rinvex.bookings.bookable-booking')->endsBetween('2017-06-21 19:28:51', '2017-07-01 12:00:00')->get(); // Get bookings starts between the given dates

$bookableAvailabilitysCancelledAfter = app('rinvex.bookings.bookable-booking')->cancelledAfter('2017-06-21 19:28:51')->get(); // Get bookings starts after the given date
$bookableAvailabilitysCancelledBefore = app('rinvex.bookings.bookable-booking')->cancelledBefore('2017-06-21 19:28:51')->get(); // Get bookings starts before the given date
$bookableAvailabilitysCancelledBetween = app('rinvex.bookings.bookable-booking')->cancelledBetween('2017-06-21 19:28:51', '2017-07-01 12:00:00')->get(); // Get bookings starts between the given dates

$room = \App\Models\Room::find(1);
$bookableAvailabilitysOfBookable = app('rinvex.bookings.bookable-booking')->ofBookable($room)->get(); // Get bookings of the given resource

$customer = \App\Models\Customer::find(1);
$bookableAvailabilitysOfCustomer = app('rinvex.bookings.bookable-booking')->ofCustomer($customer)->get(); // Get bookings of the given customer

$room = \App\Models\Room::find(1);
$room->newRate('15', '^', 2); // Increase unit price by 15% for the first 2 units
$room->newRate('-10', '>', 5); // Decrease unit price by 10% if booking is greater than 5 units

$room = \App\Models\Room::find(1);
$bookableRate = app('rinvex.bookings.bookable-rate');
$bookableRate->make(['percentage' => '15', 'operator' => '^', 'amount' => 2])
     ->bookable()->associate($room)
     ->save();

$bookable = $bookableRate->bookable; // Get the owning resource model

$room = \App\Models\Room::find(1);
$room->newPrice('mon', '09:00:00', '17:00:00', '26'); // Increase pricing on Monday from 09:00 am to 05:00 pm by 26%
$room->newPrice('wed', '11:30:00', '15:45:00', '-10.5'); // Decrease pricing on Wednesday from 11:30 am to 03:45 pm by 10.5%

$bookable = $room->bookable; // Get the owning resource model

$room = \App\Models\Room::find(1);

$room->bookings; // Get all bookings
$room->pastBookings; // Get past bookings
$room->futureBookings; // Get future bookings
$room->currentBookings; // Get current bookings
$room->cancelledBookings; // Get cancelled bookings

$room->bookingsStartsBefore('2017-06-21 19:28:51')->get(); // Get bookings starts before the given date
$room->bookingsStartsAfter('2017-06-21 19:28:51')->get(); // Get bookings starts after the given date
$room->bookingsStartsBetween('2017-06-21 19:28:51', '2017-07-01 12:00:00')->get(); // Get bookings starts between the given dates

$room->bookingsEndsBefore('2017-06-21 19:28:51')->get(); // Get bookings starts before the given date
$room->bookingsEndsAfter('2017-06-21 19:28:51')->get(); // Get bookings starts after the given date
$room->bookingsEndsBetween('2017-06-21 19:28:51', '2017-07-01 12:00:00')->get(); // Get bookings starts between the given dates

$room->bookingsCancelledBefore('2017-06-21 19:28:51')->get(); // Get bookings starts before the given date
$room->bookingsCancelledAfter('2017-06-21 19:28:51')->get(); // Get bookings starts after the given date
$room->bookingsCancelledBetween('2017-06-21 19:28:51', '2017-07-01 12:00:00')->get(); // Get bookings starts between the given dates

$customer = \App\Models\Customer::find(1);
$room->bookingsOf($customer)->get(); // Get bookings of the given customer

$room->rates; // Get all bookable Rates
$room->prices; // Get all custom prices

$customer = \App\Models\Customer::find(1);

$customer->bookings; // Get all bookings
$customer->pastBookings; // Get past bookings
$customer->futureBookings; // Get future bookings
$customer->currentBookings; // Get current bookings
$customer->cancelledBookings; // Get cancelled bookings

$customer->bookingsStartsBefore('2017-06-21 19:28:51')->get(); // Get bookings starts before the given date
$customer->bookingsStartsAfter('2017-06-21 19:28:51')->get(); // Get bookings starts after the given date
$customer->bookingsStartsBetween('2017-06-21 19:28:51', '2017-07-01 12:00:00')->get(); // Get bookings starts between the given dates

$customer->bookingsEndsBefore('2017-06-21 19:28:51')->get(); // Get bookings starts before the given date
$customer->bookingsEndsAfter('2017-06-21 19:28:51')->get(); // Get bookings starts after the given date
$customer->bookingsEndsBetween('2017-06-21 19:28:51', '2017-07-01 12:00:00')->get(); // Get bookings starts between the given dates

$customer->bookingsCancelledBefore('2017-06-21 19:28:51')->get(); // Get bookings starts before the given date
$customer->bookingsCancelledAfter('2017-06-21 19:28:51')->get(); // Get bookings starts after the given date
$customer->bookingsCancelledBetween('2017-06-21 19:28:51', '2017-07-01 12:00:00')->get(); // Get bookings starts between the given dates

$room = \App\Models\Room::find(1);
$customer->isBooked($room); // Check if the customer booked the given room
$customer->bookingsOf($room)->get(); // Get bookings by the customer for the given room
shell
    php artisan rinvex:migrate:bookings