PHP code example of zaber-dev / laravel-reservation
1. Go to this page and download the library: Download zaber-dev/laravel-reservation 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/ */
zaber-dev / laravel-reservation example snippets
Reservation::for('seat_A12')
->heldBy($user)
->forMinutes(15)
->hold();
// Process payment...
Reservation::for('seat_A12')->confirm();
use ZaberDev\Reservation\Facades\Reservation;
// 1. Place a temporary hold
$builder = Reservation::for('seat_A12')
->heldBy($user)
->forMinutes(15);
if ($builder->hold()) {
// Hold placed successfully, present payment form...
} else {
// Resource is currently held or already confirmed by another customer
}
// 2. Confirm the reservation once payment completes
if (Reservation::for('seat_A12')->confirm()) {
// Reservation is now permanently confirmed!
}
Reservation::for('seat_A12')->cancel();
$info = Reservation::for('seat_A12')->info(); // ReservationInfo DTO
if ($info->isHeld()) {
echo "Resource is reserved by " . $info->holder . " until " . $info->expiresAt->toDateTimeString();
} elseif ($info->isConfirmed()) {
echo "Resource is permanently booked.";
} elseif ($info->isExpired() || $info->isCancelled()) {
echo "Resource is available.";
}
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use ZaberDev\Reservation\HasReservations;
class Seat extends Model
{
use HasReservations;
}
$seat = Seat::find(1);
// Reserve this seat for the user for 20 minutes
if ($seat->reserve()->heldBy($user)->forMinutes(20)->hold()) {
return response()->json(['message' => 'Seat held!']);
}
// Confirm booking
$seat->reserve()->confirm();
// Cancel hold
$seat->reserve()->cancel();
// Get all database reservation records for this seat
$history = $seat->reservations()->orderBy('created_at', 'desc')->get();
use Illuminate\Support\Facades\Route;
// Enforce that "seat_A12" (or dynamic route parameter) is held during checkout submission
Route::post('/checkout/submit', [CheckoutController::class, 'submit'])
->middleware('reserve:seat_id,15');
// Store transient shopping cart holds in fast cache/Redis
Reservation::for('cart_item_99')->using('cache')->heldBy($user)->forMinutes(30)->hold();
// Store high-value hotel booking holds inside SQL database with row locks
Reservation::for('penthouse_suite')->using('database')->heldBy($user)->forMinutes(60)->hold();
use ZaberDev\Reservation\Contracts\ReservationDriverContract;
use ZaberDev\Reservation\Facades\Reservation;
public function boot(): void
{
Reservation::extend('dynamodb', function ($app) {
return new MyDynamoDbReservationDriver($app['config']['reservations.drivers.dynamodb']);
});
}
use Illuminate\Support\Facades\Schedule;
use ZaberDev\Reservation\Models\ReservationModel;
Schedule::command('model:prune', ['--model' => ReservationModel::class])->daily();