PHP code example of aaronfrancis / reservable

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

    

aaronfrancis / reservable example snippets


use AaronFrancis\Reservable\Concerns\Reservable;

class Video extends Model
{
    use Reservable;
}

// Reserve for 60 seconds (default)
$video->reserve('processing');

// Reserve for a specific duration in seconds
$video->reserve('processing', 300); // 5 minutes

// Reserve until a specific time
$video->reserve('processing', now()->addHour());

// Reserve with CarbonInterval
$video->reserve('processing', CarbonInterval::minutes(5));
$video->reserve('processing', CarbonInterval::hours(2));

if ($video->isReserved('processing')) {
    // Model is currently reserved
}

$video->releaseReservation('processing');

// Wait up to 10 seconds (default) for the lock
$video->blockingReserve('processing', duration: 60);

// Wait up to 30 seconds
$video->blockingReserve('processing', duration: 60, wait: 30);

// With CarbonInterval
$video->blockingReserve('processing', CarbonInterval::minutes(5), wait: 30);

$result = $video->reserveWhile('processing', 300, function ($video) {
    // Do work while holding the lock...
    return $video->transcode();
}); // Lock is automatically released

$video->reserve('processing', 60);

// Later, if you need more time:
$video->extendReservation('processing', 60); // Add 60 more seconds

$available = Video::unreserved('processing')->get();

$reserved = Video::reserved('processing')->get();

// Get unreserved models and reserve them atomically
$videos = Video::reserveFor('processing', 60)->limit(5)->get();

// String key
$video->reserve('processing');

// Enum key
$video->reserve(JobType::Transcoding);

// Object key (uses class name)
$video->reserve($someService);

$video->reserve('transcoding');
$video->reserve('thumbnail-generation');

$video->isReserved('transcoding'); // true
$video->isReserved('thumbnail-generation'); // true
$video->isReserved('uploading'); // false

$video->reservations; // Collection of active CacheLock models

// config/reservable.php

return [
    // The model representing cache locks
    'model' => AaronFrancis\Reservable\Models\CacheLock::class,
];
bash
php artisan vendor:publish --tag=reservable-migrations
php artisan migrate
bash
php artisan vendor:publish --tag=reservable-config