PHP code example of byrcsc / laravel-hold

1. Go to this page and download the library: Download byrcsc/laravel-hold 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/ */

    

byrcsc / laravel-hold example snippets


use ByRcsc\LaravelHold\Concerns\Holdable;

class Seat extends Model
{
    use Holdable;
}

$hold = $seat->acquireHold($user, expiresAt: now()->addMinutes(15));

if ($hold === null) {
    // No slot available.
}

$hold->extend(CarbonInterval::minutes(5)); // now expires 20 minutes from acquisition
$hold->release();

class Event extends Model
{
    use Holdable;

    public function holdCapacity(): int
    {
        return $this->seat_limit; // or any fixed integer
    }
}

$hold = $seat->acquireHold($user, expiresAt: now()->addMinutes(15), metadata: [
    'reason' => 'checkout',
    'order_ref' => $orderRef,
]);

$hold = $seat->activeHoldFor($user) ?? $seat->acquireHold($user, expiresAt: now()->addMinutes(15));

Schedule::command('hold:expire')->everyMinute();

$hold->extend(CarbonInterval::minutes(10));

$hold->release();
$hold->release(by: $request->user(), metadata: ['reason' => 'cancelled by support']);

use ByRcsc\LaravelHold\Concerns\HasHolds;

class User extends Model
{
    use HasHolds;
}
bash
composer vendor:publish --tag="hold-migrations"
php artisan migrate
bash
php artisan vendor:publish --tag="hold-config"
bash
php artisan hold:prune --days=30